CMS 3D CMS Logo

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

Public Member Functions

 DeepTauId (const edm::ParameterSet &cfg, const deep_tau::DeepTauCache *cache)
 
void produce (edm::Event &event, const edm::EventSetup &es) override
 
- Public Member Functions inherited from DeepTauIdBase< DeepTauIdWrapper >
 DeepTauIdBase (const edm::ParameterSet &cfg)
 
const std::map< BasicDiscriminator, size_t > matchDiscriminatorIndices (edm::Event const &event, edm::EDGetTokenT< reco::TauDiscriminatorContainer > discriminatorContainerToken, std::vector< BasicDiscriminator > requiredDiscr)
 
- Public Member Functions inherited from DeepTauIdWrapper
 DeepTauIdWrapper (const edm::ParameterSet &cfg)
 
- 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 void globalEndJob (const deep_tau::DeepTauCache *cache_)
 
static std::unique_ptr< deep_tau::DeepTauCacheinitializeGlobalCache (const edm::ParameterSet &cfg)
 
- Static Public Member Functions inherited from DeepTauIdBase< DeepTauIdWrapper >
static void fillDescriptionsHelper (edm::ParameterSetDescription &desc)
 
static const IDOutputCollectionGetIDOutputs ()
 

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)
 
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)
 

Private Attributes

const deep_tau::DeepTauCachecache_
 
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > convTensor_
 
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > eGammaTensor_
 
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > hadronsTensor_
 
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > muonTensor_
 
std::unique_ptr< tensorflow::Tensor > tauBlockTensor_
 
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > zeroOutputTensor_
 

Additional Inherited Members

- Public Types inherited from DeepTauIdBase< DeepTauIdWrapper >
using BasicDiscriminator = deep_tau::BasicDiscriminator
 
using CandidateCollection = edm::View< reco::Candidate >
 
using Cutter = tau::TauWPThreshold
 
using CutterPtr = std::unique_ptr< Cutter >
 
using ElectronCollection = pat::ElectronCollection
 
using IDOutputCollection = std::map< std::string, IDOutput >
 
using LorentzVectorXYZ = ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > >
 
using MuonCollection = pat::MuonCollection
 
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 Attributes inherited from DeepTauIdBase< DeepTauIdWrapper >
uint8_t andPrediscriminants_
 
std::vector< TauDiscInfo< pat::PATTauDiscriminator > > patPrediscriminants_
 
std::vector< TauDiscInfo< reco::PFTauDiscriminator > > recoPrediscriminants_
 
- Static Public Attributes inherited from DeepTauIdBase< DeepTauIdWrapper >
static constexpr float default_value
 
- Protected Member Functions inherited from DeepTauIdBase< DeepTauIdWrapper >
void createEgammaBlockInputs (unsigned idx, const TauCastType &tau, const size_t tau_index, const edm::RefToBase< reco::BaseTau > tau_ref, const reco::Vertex &pv, double rho, const std::vector< pat::Electron > *electrons, const edm::View< reco::Candidate > &pfCands, const Cell &cell_map, TauFunc tau_funcs, bool is_inner, EgammaBlockType &egammaBlockInputs)
 
void createHadronsBlockInputs (unsigned idx, const TauCastType &tau, const size_t tau_index, const edm::RefToBase< reco::BaseTau > tau_ref, const reco::Vertex &pv, double rho, const edm::View< reco::Candidate > &pfCands, const Cell &cell_map, TauFunc tau_funcs, bool is_inner, HadronBlockType &hadronBlockInputs)
 
void createMuonBlockInputs (unsigned idx, const TauCastType &tau, const size_t tau_index, const edm::RefToBase< reco::BaseTau > tau_ref, const reco::Vertex &pv, double rho, const std::vector< pat::Muon > *muons, const edm::View< reco::Candidate > &pfCands, const Cell &cell_map, TauFunc tau_funcs, bool is_inner, MuonBlockType &muonBlockInputs)
 
void createOutputs (edm::Event &event, const PredType &pred, edm::Handle< TauCollection > taus)
 
void createTauBlockInputs (const TauCastType &tau, const size_t &tau_index, const edm::RefToBase< reco::BaseTau > tau_ref, const reco::Vertex &pv, double rho, TauFunc tau_funcs, TauBlockType &tauBlockInputs)
 
void fillGrids (const TauCastType &tau, const Collection &objects, CellGrid &inner_grid, CellGrid &outer_grid)
 
void loadPrediscriminants (edm::Event const &event, edm::Handle< TauCollection > const &taus)
 
- Static Protected Member Functions inherited from DeepTauIdBase< DeepTauIdWrapper >
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)
 
static bool calculateGottfriedJacksonAngleDifference (const TauCastType &tau, const size_t tau_index, double &gj_diff, TauFunc tau_funcs)
 
static float calculateGottfriedJacksonAngleDifference (const TauCastType &tau, const size_t tau_index, TauFunc tau_funcs)
 
static const pat::ElectronfindMatchedElectron (const TauCastType &tau, const std::vector< pat::Electron > *electrons, double deltaR)
 
static double getInnerSignalConeRadius (double pt)
 
static float getValue (T value)
 
static float getValueLinear (T value, float min_value, float max_value, bool positive)
 
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)
 
static void processIsolationPFComponents (const TauCastType &tau, const CandidateCollection &candidates, LorentzVectorXYZ &p4, float &pt, float &d_eta, float &d_phi, float &m, float &n)
 
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)
 
- Protected Attributes inherited from DeepTauIdBase< DeepTauIdWrapper >
std::map< BasicDiscriminator, size_t > basicDiscrdR03IndexMap_
 
std::map< BasicDiscriminator, size_t > basicDiscrIndexMap_
 
edm::EDGetTokenT< reco::TauDiscriminatorContainerbasicTauDiscriminators_inputToken_
 
edm::EDGetTokenT< reco::TauDiscriminatorContainerbasicTauDiscriminatorsdR03_inputToken_
 
const int debug_level
 
const bool disable_CellIndex_workaround_
 
const bool disable_dxy_pca_
 
const bool disable_hcalFraction_workaround_
 
bool discrIndicesMapped_
 
edm::EDGetTokenT< std::vector< pat::Electron > > electrons_token_
 
int file_counter_
 
IDOutputCollection idoutputs_
 
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::string output_layer_
 
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::vector< int > tauInputs_indices_
 
edm::EDGetTokenT< TauCollectiontausToken_
 
const unsigned version_
 
edm::EDGetTokenT< reco::VertexCollectionvtxToken_
 
std::map< std::string, WPListworkingPoints_
 
const unsigned year_
 
- Static Protected Attributes inherited from DeepTauIdBase< DeepTauIdWrapper >
static constexpr float pi
 

Detailed Description

Definition at line 78 of file DeepTauId.cc.

Constructor & Destructor Documentation

◆ DeepTauId()

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

Definition at line 89 of file DeepTauId.cc.

References convTensor_, eGammaTensor_, getPartialPredictions(), hadronsTensor_, muonTensor_, dqmiodumpmetadata::n, setCellConvFeatures(), findQualityFiles::size, DeepTauIdBase< DeepTauIdWrapper >::sub_version_, tauBlockTensor_, DeepTauIdBase< DeepTauIdWrapper >::version_, and zeroOutputTensor_.

91  if (version_ == 2) {
92  using namespace dnn_inputs_v2;
93  if (sub_version_ == 1) {
94  tauBlockTensor_ = std::make_unique<tensorflow::Tensor>(
95  tensorflow::DT_FLOAT, tensorflow::TensorShape{1, TauBlockInputs::NumberOfInputs});
96  } else if (sub_version_ == 5) {
97  tauBlockTensor_ = std::make_unique<tensorflow::Tensor>(
98  tensorflow::DT_FLOAT,
99  tensorflow::TensorShape{1,
100  static_cast<int>(TauBlockInputs::NumberOfInputs) -
101  static_cast<int>(TauBlockInputs::varsToDrop.size())});
102  }
103 
104  for (size_t n = 0; n < 2; ++n) {
105  const bool is_inner = n == 0;
106  const auto n_cells = is_inner ? number_of_inner_cell : number_of_outer_cell;
107  eGammaTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
108  tensorflow::DT_FLOAT, tensorflow::TensorShape{1, 1, 1, EgammaBlockInputs::NumberOfInputs});
109  muonTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
110  tensorflow::DT_FLOAT, tensorflow::TensorShape{1, 1, 1, MuonBlockInputs::NumberOfInputs});
111  hadronsTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
112  tensorflow::DT_FLOAT, tensorflow::TensorShape{1, 1, 1, HadronBlockInputs::NumberOfInputs});
113  convTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
114  tensorflow::DT_FLOAT, tensorflow::TensorShape{1, n_cells, n_cells, number_of_conv_features});
115  zeroOutputTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
116  tensorflow::DT_FLOAT, tensorflow::TensorShape{1, 1, 1, number_of_conv_features});
117 
118  eGammaTensor_[is_inner]->flat<float>().setZero();
119  muonTensor_[is_inner]->flat<float>().setZero();
120  hadronsTensor_[is_inner]->flat<float>().setZero();
121 
122  setCellConvFeatures(*zeroOutputTensor_[is_inner], getPartialPredictions(is_inner), 0, 0, 0);
123  }
124  }
125  }
size
Write out results.
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > hadronsTensor_
Definition: DeepTauId.cc:653
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > zeroOutputTensor_
Definition: DeepTauId.cc:653
void setCellConvFeatures(tensorflow::Tensor &convTensor, const tensorflow::Tensor &features, unsigned batch_idx, int eta_index, int phi_index)
Definition: DeepTauId.cc:639
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > convTensor_
Definition: DeepTauId.cc:653
const deep_tau::DeepTauCache * cache_
Definition: DeepTauId.cc:650
tensorflow::Tensor getPartialPredictions(bool is_inner)
Definition: DeepTauId.cc:512
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > eGammaTensor_
Definition: DeepTauId.cc:653
def cache(function)
Definition: utilities.py:3
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > muonTensor_
Definition: DeepTauId.cc:653
std::unique_ptr< tensorflow::Tensor > tauBlockTensor_
Definition: DeepTauId.cc:652

Member Function Documentation

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

References cms::cuda::assert(), gather_cfg::cout, DeepTauIdBase< DeepTauIdWrapper >::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().

172  {
173  if (debug_level >= 1) {
174  std::cout << "<checkInputs>: block_name = " << block_name << std::endl;
175  if (block_name == "input_tau") {
176  for (int input_index = 0; input_index < n_inputs; ++input_index) {
177  float input = inputs.matrix<float>()(0, input_index);
178  if (edm::isNotFinite(input)) {
179  throw cms::Exception("DeepTauId")
180  << "in the " << block_name
181  << ", input is not finite, i.e. infinite or NaN, for input_index = " << input_index;
182  }
183  if (debug_level >= 2) {
184  std::cout << block_name << "[var = " << input_index << "] = " << std::setprecision(5) << std::fixed << input
185  << std::endl;
186  }
187  }
188  } else {
189  assert(grid);
190  int n_eta, n_phi;
191  if (block_name.find("input_inner") != std::string::npos) {
192  n_eta = 5;
193  n_phi = 5;
194  } else if (block_name.find("input_outer") != std::string::npos) {
195  n_eta = 10;
196  n_phi = 10;
197  } else
198  assert(0);
199  int eta_phi_index = 0;
200  for (int eta = -n_eta; eta <= n_eta; ++eta) {
201  for (int phi = -n_phi; phi <= n_phi; ++phi) {
202  const CellIndex cell_index{eta, phi};
203  const auto cell_iter = grid->find(cell_index);
204  if (cell_iter != grid->end()) {
205  for (int input_index = 0; input_index < n_inputs; ++input_index) {
206  float input = inputs.tensor<float, 4>()(eta_phi_index, 0, 0, input_index);
207  if (edm::isNotFinite(input)) {
208  throw cms::Exception("DeepTauId")
209  << "in the " << block_name << ", input is not finite, i.e. infinite or NaN, for eta = " << eta
210  << ", phi = " << phi << ", input_index = " << input_index;
211  }
212  if (debug_level >= 2) {
213  std::cout << block_name << "[eta = " << eta << "][phi = " << phi << "][var = " << input_index
214  << "] = " << std::setprecision(5) << std::fixed << input << std::endl;
215  }
216  }
217  eta_phi_index += 1;
218  }
219  }
220  }
221  }
222  }
223  }
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
assert(be >=bs)
static std::string const input
Definition: EdmProvDump.cc:50

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

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

548  {
549  if (debug_level >= 2) {
550  std::cout << "<DeepTauId::createConvFeatures (is_inner = " << is_inner << ")>:" << std::endl;
551  std::cout << "number of valid cells = " << grid.num_valid_cells() << std::endl;
552  }
553 
554  const size_t n_valid_cells = grid.num_valid_cells();
555  tensorflow::Tensor predTensor;
556  tensorflow::Tensor& convTensor = *convTensor_.at(is_inner);
557 
558  //check if at least one input is there to
559  //avoid calling TF with empty grid #TODO understand why the grid is empty
560  if (n_valid_cells > 0) {
561  eGammaTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
562  tensorflow::DT_FLOAT,
563  tensorflow::TensorShape{
564  (long long int)grid.num_valid_cells(), 1, 1, dnn_inputs_v2::EgammaBlockInputs::NumberOfInputs});
565  muonTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
566  tensorflow::DT_FLOAT,
567  tensorflow::TensorShape{
568  (long long int)grid.num_valid_cells(), 1, 1, dnn_inputs_v2::MuonBlockInputs::NumberOfInputs});
569  hadronsTensor_[is_inner] = std::make_unique<tensorflow::Tensor>(
570  tensorflow::DT_FLOAT,
571  tensorflow::TensorShape{
572  (long long int)grid.num_valid_cells(), 1, 1, dnn_inputs_v2::HadronBlockInputs::NumberOfInputs});
573 
574  eGammaTensor_[is_inner]->flat<float>().setZero();
575  muonTensor_[is_inner]->flat<float>().setZero();
576  hadronsTensor_[is_inner]->flat<float>().setZero();
577 
578  unsigned idx = 0;
579  for (int eta = -grid.maxEtaIndex(); eta <= grid.maxEtaIndex(); ++eta) {
580  for (int phi = -grid.maxPhiIndex(); phi <= grid.maxPhiIndex(); ++phi) {
581  if (debug_level >= 2) {
582  std::cout << "processing ( eta = " << eta << ", phi = " << phi << " )" << std::endl;
583  }
584  const CellIndex cell_index{eta, phi};
585  const auto cell_iter = grid.find(cell_index);
586  if (cell_iter != grid.end()) {
587  if (debug_level >= 2) {
588  std::cout << " creating inputs for ( eta = " << eta << ", phi = " << phi << " ): idx = " << idx
589  << std::endl;
590  }
591  const Cell& cell = cell_iter->second;
592  createEgammaBlockInputs<CandidateCastType>(idx,
593  tau,
594  tau_index,
595  tau_ref,
596  pv,
597  rho,
598  electrons,
599  pfCands,
600  cell,
601  tau_funcs,
602  is_inner,
603  *eGammaTensor_[is_inner]);
604  createMuonBlockInputs<CandidateCastType>(
605  idx, tau, tau_index, tau_ref, pv, rho, muons, pfCands, cell, tau_funcs, is_inner, *muonTensor_[is_inner]);
606  createHadronsBlockInputs<CandidateCastType>(
607  idx, tau, tau_index, tau_ref, pv, rho, pfCands, cell, tau_funcs, is_inner, *hadronsTensor_[is_inner]);
608  idx += 1;
609  } else {
610  if (debug_level >= 2) {
611  std::cout << " skipping creation of inputs, because ( eta = " << eta << ", phi = " << phi
612  << " ) is not in the grid !!" << std::endl;
613  }
614  }
615  }
616  }
617  // Calling TF prediction only if n_valid_cells > 0
618  predTensor = getPartialPredictions(is_inner);
619  }
620 
621  unsigned idx = 0;
622  for (int eta = -grid.maxEtaIndex(); eta <= grid.maxEtaIndex(); ++eta) {
623  for (int phi = -grid.maxPhiIndex(); phi <= grid.maxPhiIndex(); ++phi) {
624  const CellIndex cell_index{eta, phi};
625  const int eta_index = grid.getEtaTensorIndex(cell_index);
626  const int phi_index = grid.getPhiTensorIndex(cell_index);
627 
628  const auto cell_iter = grid.find(cell_index);
629  if (cell_iter != grid.end()) {
630  setCellConvFeatures(convTensor, predTensor, idx, eta_index, phi_index);
631  idx += 1;
632  } else {
633  setCellConvFeatures(convTensor, *zeroOutputTensor_[is_inner], 0, eta_index, phi_index);
634  }
635  }
636  }
637  }
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > hadronsTensor_
Definition: DeepTauId.cc:653
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > zeroOutputTensor_
Definition: DeepTauId.cc:653
void setCellConvFeatures(tensorflow::Tensor &convTensor, const tensorflow::Tensor &features, unsigned batch_idx, int eta_index, int phi_index)
Definition: DeepTauId.cc:639
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
Definition: DiMuonV_cfg.py:214
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > convTensor_
Definition: DeepTauId.cc:653
def pv(vc)
Definition: MetAnalyzer.py:7
tensorflow::Tensor getPartialPredictions(bool is_inner)
Definition: DeepTauId.cc:512
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > eGammaTensor_
Definition: DeepTauId.cc:653
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > muonTensor_
Definition: DeepTauId.cc:653

◆ fillDescriptions()

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

Definition at line 80 of file DeepTauId.cc.

References edm::ConfigurationDescriptions::add(), submitPVResolutionJobs::desc, and DeepTauIdBase< DeepTauIdWrapper >::fillDescriptionsHelper().

80  {
83  desc.add<std::vector<std::string>>("graph_file",
84  {"RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6.pb"});
85  descriptions.add("DeepTau", desc);
86  }
static void fillDescriptionsHelper(edm::ParameterSetDescription &desc)
void add(std::string const &label, ParameterSetDescription const &psetDescription)

◆ getPartialPredictions()

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

Definition at line 512 of file DeepTauId.cc.

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

Referenced by createConvFeatures(), and DeepTauId().

512  {
513  std::vector<tensorflow::Tensor> pred_vector;
514  if (is_inner) {
515  tensorflow::run(&(cache_->getSession("inner")),
516  {
517  {"input_inner_egamma", *eGammaTensor_.at(is_inner)},
518  {"input_inner_muon", *muonTensor_.at(is_inner)},
519  {"input_inner_hadrons", *hadronsTensor_.at(is_inner)},
520  },
521  {"inner_all_dropout_4/Identity"},
522  &pred_vector);
523  } else {
524  tensorflow::run(&(cache_->getSession("outer")),
525  {
526  {"input_outer_egamma", *eGammaTensor_.at(is_inner)},
527  {"input_outer_muon", *muonTensor_.at(is_inner)},
528  {"input_outer_hadrons", *hadronsTensor_.at(is_inner)},
529  },
530  {"outer_all_dropout_4/Identity"},
531  &pred_vector);
532  }
533 
534  return pred_vector.at(0);
535  }
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > hadronsTensor_
Definition: DeepTauId.cc:653
const deep_tau::DeepTauCache * cache_
Definition: DeepTauId.cc:650
void run(Session *session, const NamedTensorList &inputs, const std::vector< std::string > &outputNames, std::vector< Tensor > *outputs, const thread::ThreadPoolOptions &threadPoolOptions)
Definition: TensorFlow.cc:271
tensorflow::Session & getSession(const std::string &name="") const
Definition: DeepTauId.cc:63
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > eGammaTensor_
Definition: DeepTauId.cc:653
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > muonTensor_
Definition: DeepTauId.cc:653

◆ getPredictions()

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

Definition at line 286 of file DeepTauId.cc.

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

Referenced by produce().

286  {
287  // Empty dummy vectors
288  const std::vector<pat::Electron> electron_collection_default;
289  const std::vector<pat::Muon> muon_collection_default;
290  const reco::TauDiscriminatorContainer basicTauDiscriminators_default;
291  const reco::TauDiscriminatorContainer basicTauDiscriminatorsdR03_default;
293  pfTauTransverseImpactParameters_default;
294 
295  const std::vector<pat::Electron>* electron_collection;
296  const std::vector<pat::Muon>* muon_collection;
301 
302  if (!is_online_) {
303  electron_collection = &event.get(electrons_token_);
304  muon_collection = &event.get(muons_token_);
305  pfTauTransverseImpactParameters = &pfTauTransverseImpactParameters_default;
306  basicTauDiscriminators = &basicTauDiscriminators_default;
307  basicTauDiscriminatorsdR03 = &basicTauDiscriminatorsdR03_default;
308  } else {
309  electron_collection = &electron_collection_default;
310  muon_collection = &muon_collection_default;
314 
315  // Get indices for discriminators
316  if (!discrIndicesMapped_) {
321  discrIndicesMapped_ = true;
322  }
323  }
324 
325  TauFunc tauIDs = {basicTauDiscriminators,
330 
332  event.getByToken(pfcandToken_, pfCands);
333 
335  event.getByToken(vtxToken_, vertices);
336 
338  event.getByToken(rho_token_, rho);
339 
340  auto const& eventnr = event.id().event();
341 
342  tensorflow::Tensor predictions(tensorflow::DT_FLOAT, {static_cast<int>(taus->size()), deep_tau::NumberOfOutputs});
343 
344  for (size_t tau_index = 0; tau_index < taus->size(); ++tau_index) {
345  const edm::RefToBase<reco::BaseTau> tauRef = taus->refAt(tau_index);
346 
347  std::vector<tensorflow::Tensor> pred_vector;
348 
349  bool passesPrediscriminants;
350  if (is_online_) {
351  passesPrediscriminants = tauIDs.passPrediscriminants<std::vector<TauDiscInfo<reco::PFTauDiscriminator>>>(
353  } else {
354  passesPrediscriminants = tauIDs.passPrediscriminants<std::vector<TauDiscInfo<pat::PATTauDiscriminator>>>(
356  }
357 
358  if (passesPrediscriminants) {
359  if (version_ == 2) {
360  if (is_online_) {
361  getPredictionsV2<reco::PFCandidate, reco::PFTau>(taus->at(tau_index),
362  tau_index,
363  tauRef,
364  electron_collection,
365  muon_collection,
366  *pfCands,
367  vertices->at(0),
368  *rho,
369  eventnr,
370  pred_vector,
371  tauIDs);
372  } else
373  getPredictionsV2<pat::PackedCandidate, pat::Tau>(taus->at(tau_index),
374  tau_index,
375  tauRef,
376  electron_collection,
377  muon_collection,
378  *pfCands,
379  vertices->at(0),
380  *rho,
381  eventnr,
382  pred_vector,
383  tauIDs);
384  } else {
385  throw cms::Exception("DeepTauId") << "version " << version_ << " is not supported.";
386  }
387 
388  for (int k = 0; k < deep_tau::NumberOfOutputs; ++k) {
389  const float pred = pred_vector[0].flat<float>()(k);
390  if (!(pred >= 0 && pred <= 1))
391  throw cms::Exception("DeepTauId")
392  << "invalid prediction = " << pred << " for tau_index = " << tau_index << ", pred_index = " << k;
393  predictions.matrix<float>()(tau_index, k) = pred;
394  }
395  } else {
396  // This else statement was added as a part of the DeepTau@HLT development. It does not affect the current state
397  // of offline DeepTauId code as there the preselection is not used (it was added in the DeepTau@HLT). It returns
398  // default values for deepTau score if the preselection failed. Before this statement the values given for this tau
399  // were random. k == 2 corresponds to the tau score and all other k values to e, mu and jets. By defining in this way
400  // the final score is -1.
401  for (int k = 0; k < deep_tau::NumberOfOutputs; ++k) {
402  predictions.matrix<float>()(tau_index, k) = (k == 2) ? -1.f : 2.f;
403  }
404  }
405  }
406  return predictions;
407  }
edm::EDGetTokenT< std::vector< pat::Electron > > electrons_token_
std::vector< TauDiscInfo< pat::PATTauDiscriminator > > patPrediscriminants_
edm::EDGetTokenT< double > rho_token_
std::map< BasicDiscriminator, size_t > basicDiscrIndexMap_
const std::vector< BasicDiscriminator > requiredBasicDiscriminators_
edm::EDGetTokenT< CandidateCollection > pfcandToken_
edm::EDGetTokenT< std::vector< pat::Muon > > muons_token_
edm::EDGetTokenT< reco::TauDiscriminatorContainer > basicTauDiscriminators_inputToken_
std::map< BasicDiscriminator, size_t > basicDiscrdR03IndexMap_
const std::vector< BasicDiscriminator > requiredBasicDiscriminatorsdR03_
double f[11][100]
edm::EDGetTokenT< reco::TauDiscriminatorContainer > basicTauDiscriminatorsdR03_inputToken_
const std::map< BasicDiscriminator, size_t > matchDiscriminatorIndices(edm::Event const &event, edm::EDGetTokenT< reco::TauDiscriminatorContainer > discriminatorContainerToken, std::vector< BasicDiscriminator > requiredDiscr)
edm::EDGetTokenT< reco::VertexCollection > vtxToken_
std::vector< TauDiscInfo< reco::PFTauDiscriminator > > recoPrediscriminants_
Definition: event.py:1
constexpr int NumberOfOutputs
Definition: DeepTauIdBase.h:50
edm::EDGetTokenT< edm::AssociationVector< reco::PFTauRefProd, std::vector< reco::PFTauTransverseImpactParameterRef > > > pfTauTransverseImpactParameters_token_

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

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

420  {
421  using namespace dnn_inputs_v2;
422  if (debug_level >= 2) {
423  std::cout << "<DeepTauId::getPredictionsV2 (moduleLabel = " << moduleDescription().moduleLabel()
424  << ")>:" << std::endl;
425  std::cout << " tau: pT = " << tau.pt() << ", eta = " << tau.eta() << ", phi = " << tau.phi()
426  << ", eventnr = " << eventnr << std::endl;
427  }
428  CellGrid inner_grid(number_of_inner_cell, number_of_inner_cell, 0.02, 0.02, disable_CellIndex_workaround_);
429  CellGrid outer_grid(number_of_outer_cell, number_of_outer_cell, 0.05, 0.05, disable_CellIndex_workaround_);
430  fillGrids(dynamic_cast<const TauCastType&>(tau), *electrons, inner_grid, outer_grid);
431  fillGrids(dynamic_cast<const TauCastType&>(tau), *muons, inner_grid, outer_grid);
432  fillGrids(dynamic_cast<const TauCastType&>(tau), pfCands, inner_grid, outer_grid);
433 
434  tauBlockTensor_->flat<float>().setZero();
435  createTauBlockInputs<CandidateCastType>(
436  dynamic_cast<const TauCastType&>(tau), tau_index, tau_ref, pv, rho, tau_funcs, *tauBlockTensor_);
437  checkInputs(*tauBlockTensor_, "input_tau", static_cast<int>(tauBlockTensor_->shape().dim_size(1)));
438  createConvFeatures<CandidateCastType>(dynamic_cast<const TauCastType&>(tau),
439  tau_index,
440  tau_ref,
441  pv,
442  rho,
443  electrons,
444  muons,
445  pfCands,
446  inner_grid,
447  tau_funcs,
448  true);
449  checkInputs(*eGammaTensor_[true], "input_inner_egamma", EgammaBlockInputs::NumberOfInputs, &inner_grid);
450  checkInputs(*muonTensor_[true], "input_inner_muon", MuonBlockInputs::NumberOfInputs, &inner_grid);
451  checkInputs(*hadronsTensor_[true], "input_inner_hadrons", HadronBlockInputs::NumberOfInputs, &inner_grid);
452  createConvFeatures<CandidateCastType>(dynamic_cast<const TauCastType&>(tau),
453  tau_index,
454  tau_ref,
455  pv,
456  rho,
457  electrons,
458  muons,
459  pfCands,
460  outer_grid,
461  tau_funcs,
462  false);
463  checkInputs(*eGammaTensor_[false], "input_outer_egamma", EgammaBlockInputs::NumberOfInputs, &outer_grid);
464  checkInputs(*muonTensor_[false], "input_outer_muon", MuonBlockInputs::NumberOfInputs, &outer_grid);
465  checkInputs(*hadronsTensor_[false], "input_outer_hadrons", HadronBlockInputs::NumberOfInputs, &outer_grid);
466 
467  if (save_inputs_) {
468  std::string json_file_name = "DeepTauId_" + std::to_string(eventnr) + "_" + std::to_string(tau_index) + ".json";
469  json_file_ = new std::ofstream(json_file_name.data());
470  is_first_block_ = true;
471  (*json_file_) << "{";
472  saveInputs(*tauBlockTensor_, "input_tau", static_cast<int>(tauBlockTensor_->shape().dim_size(1)));
473  saveInputs(*eGammaTensor_[true], "input_inner_egamma", EgammaBlockInputs::NumberOfInputs, &inner_grid);
474  saveInputs(*muonTensor_[true], "input_inner_muon", MuonBlockInputs::NumberOfInputs, &inner_grid);
475  saveInputs(*hadronsTensor_[true], "input_inner_hadrons", HadronBlockInputs::NumberOfInputs, &inner_grid);
476  saveInputs(*eGammaTensor_[false], "input_outer_egamma", EgammaBlockInputs::NumberOfInputs, &outer_grid);
477  saveInputs(*muonTensor_[false], "input_outer_muon", MuonBlockInputs::NumberOfInputs, &outer_grid);
478  saveInputs(*hadronsTensor_[false], "input_outer_hadrons", HadronBlockInputs::NumberOfInputs, &outer_grid);
479  (*json_file_) << "}";
480  delete json_file_;
481  ++file_counter_;
482  }
483 
484  tensorflow::run(&(cache_->getSession("core")),
485  {{"input_tau", *tauBlockTensor_},
486  {"input_inner", *convTensor_.at(true)},
487  {"input_outer", *convTensor_.at(false)}},
488  {"main_output/Softmax"},
489  &pred_vector);
490  if (debug_level >= 1) {
491  std::cout << "output = { ";
492  for (int idx = 0; idx < deep_tau::NumberOfOutputs; ++idx) {
493  if (idx > 0)
494  std::cout << ", ";
496  if (idx == 0)
497  label = "e";
498  else if (idx == 1)
499  label = "mu";
500  else if (idx == 2)
501  label = "tau";
502  else if (idx == 3)
503  label = "jet";
504  else
505  assert(0);
506  std::cout << label << " = " << pred_vector[0].flat<float>()(idx);
507  }
508  std::cout << " }" << std::endl;
509  }
510  }
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > hadronsTensor_
Definition: DeepTauId.cc:653
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
Definition: DiMuonV_cfg.py:214
assert(be >=bs)
static std::string to_string(const XMLCh *ch)
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > convTensor_
Definition: DeepTauId.cc:653
const deep_tau::DeepTauCache * cache_
Definition: DeepTauId.cc:650
char const * label
void run(Session *session, const NamedTensorList &inputs, const std::vector< std::string > &outputNames, std::vector< Tensor > *outputs, const thread::ThreadPoolOptions &threadPoolOptions)
Definition: TensorFlow.cc:271
void saveInputs(const tensorflow::Tensor &inputs, const std::string &block_name, int n_inputs, const CellGrid *grid=nullptr)
Definition: DeepTauId.cc:225
void checkInputs(const tensorflow::Tensor &inputs, const std::string &block_name, int n_inputs, const CellGrid *grid=nullptr) const
Definition: DeepTauId.cc:169
tensorflow::Session & getSession(const std::string &name="") const
Definition: DeepTauId.cc:63
void fillGrids(const TauCastType &tau, const Collection &objects, CellGrid &inner_grid, CellGrid &outer_grid)
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > eGammaTensor_
Definition: DeepTauId.cc:653
std::array< std::unique_ptr< tensorflow::Tensor >, 2 > muonTensor_
Definition: DeepTauId.cc:653
constexpr int NumberOfOutputs
Definition: DeepTauIdBase.h:50
std::unique_ptr< tensorflow::Tensor > tauBlockTensor_
Definition: DeepTauId.cc:652

◆ globalEndJob()

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

Definition at line 166 of file DeepTauId.cc.

166 {}

◆ initializeGlobalCache()

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

Definition at line 144 of file DeepTauId.cc.

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

144  {
145  const auto graph_name_vector = cfg.getParameter<std::vector<std::string>>("graph_file");
146  std::map<std::string, std::string> graph_names;
147  for (const auto& entry : graph_name_vector) {
148  const size_t sep_pos = entry.find(':');
149  std::string entry_name, graph_file;
150  if (sep_pos != std::string::npos) {
151  entry_name = entry.substr(0, sep_pos);
152  graph_file = entry.substr(sep_pos + 1);
153  } else {
154  entry_name = "";
155  graph_file = entry;
156  }
158  if (graph_names.count(entry_name))
159  throw cms::Exception("DeepTauCache") << "Duplicated graph entries";
160  graph_names[entry_name] = graph_file;
161  }
162  bool mem_mapped = cfg.getParameter<bool>("mem_mapped");
163  return std::make_unique<deep_tau::DeepTauCache>(graph_names, mem_mapped);
164  }
std::string fullPath() const
Definition: FileInPath.cc:161

◆ produce()

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

Definition at line 127 of file DeepTauId.cc.

References DeepTauIdBase< DeepTauIdWrapper >::createOutputs(), getPredictions(), DeepTauIdBase< DeepTauIdWrapper >::loadPrediscriminants(), deep_tau::NumberOfOutputs, Tau3MuMonitor_cff::taus, and DeepTauIdBase< DeepTauIdWrapper >::tausToken_.

127  {
129  event.getByToken(tausToken_, taus);
130 
131  // store empty output collection(s) if tau collection is empty
132  if (taus->empty()) {
133  const tensorflow::Tensor emptyPrediction(tensorflow::DT_FLOAT, {0, deep_tau::NumberOfOutputs});
134  createOutputs(event, emptyPrediction, taus);
135  return;
136  }
137 
139 
140  const tensorflow::Tensor& pred = getPredictions(event, taus);
141  createOutputs(event, pred, taus);
142  }
tensorflow::Tensor getPredictions(edm::Event &event, edm::Handle< TauCollection > taus)
Definition: DeepTauId.cc:286
edm::EDGetTokenT< TauCollection > tausToken_
void createOutputs(edm::Event &event, const PredType &pred, edm::Handle< TauCollection > taus)
void loadPrediscriminants(edm::Event const &event, edm::Handle< TauCollection > const &taus)
Definition: event.py:1
constexpr int NumberOfOutputs
Definition: DeepTauIdBase.h:50

◆ saveInputs()

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

Definition at line 225 of file DeepTauId.cc.

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

Referenced by getPredictionsV2().

228  {
229  if (debug_level >= 1) {
230  std::cout << "<saveInputs>: block_name = " << block_name << std::endl;
231  }
232  if (!is_first_block_)
233  (*json_file_) << ", ";
234  (*json_file_) << "\"" << block_name << "\": [";
235  if (block_name == "input_tau") {
236  for (int input_index = 0; input_index < n_inputs; ++input_index) {
237  float input = inputs.matrix<float>()(0, input_index);
238  if (input_index != 0)
239  (*json_file_) << ", ";
240  (*json_file_) << input;
241  }
242  } else {
243  assert(grid);
244  int n_eta, n_phi;
245  if (block_name.find("input_inner") != std::string::npos) {
246  n_eta = 5;
247  n_phi = 5;
248  } else if (block_name.find("input_outer") != std::string::npos) {
249  n_eta = 10;
250  n_phi = 10;
251  } else
252  assert(0);
253  int eta_phi_index = 0;
254  for (int eta = -n_eta; eta <= n_eta; ++eta) {
255  if (eta != -n_eta)
256  (*json_file_) << ", ";
257  (*json_file_) << "[";
258  for (int phi = -n_phi; phi <= n_phi; ++phi) {
259  if (phi != -n_phi)
260  (*json_file_) << ", ";
261  (*json_file_) << "[";
262  const CellIndex cell_index{eta, phi};
263  const auto cell_iter = grid->find(cell_index);
264  for (int input_index = 0; input_index < n_inputs; ++input_index) {
265  float input = 0.;
266  if (cell_iter != grid->end()) {
267  input = inputs.tensor<float, 4>()(eta_phi_index, 0, 0, input_index);
268  }
269  if (input_index != 0)
270  (*json_file_) << ", ";
271  (*json_file_) << input;
272  }
273  if (cell_iter != grid->end()) {
274  eta_phi_index += 1;
275  }
276  (*json_file_) << "]";
277  }
278  (*json_file_) << "]";
279  }
280  }
281  (*json_file_) << "]";
282  is_first_block_ = false;
283  }
assert(be >=bs)
static std::string const input
Definition: EdmProvDump.cc:50

◆ setCellConvFeatures()

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

Definition at line 639 of file DeepTauId.cc.

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

Referenced by createConvFeatures(), and DeepTauId().

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

Member Data Documentation

◆ cache_

const deep_tau::DeepTauCache* DeepTauId::cache_
private

Definition at line 650 of file DeepTauId.cc.

Referenced by getPartialPredictions(), and getPredictionsV2().

◆ convTensor_

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

Definition at line 653 of file DeepTauId.cc.

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

◆ eGammaTensor_

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

◆ hadronsTensor_

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

◆ muonTensor_

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

◆ tauBlockTensor_

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

Definition at line 652 of file DeepTauId.cc.

Referenced by DeepTauId(), and getPredictionsV2().

◆ zeroOutputTensor_

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

Definition at line 653 of file DeepTauId.cc.

Referenced by createConvFeatures(), and DeepTauId().