CMS 3D CMS Logo

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

Public Member Functions

 DeepTauId (const edm::ParameterSet &cfg, const deep_tau::DeepTauCache *cache)
 
- Public Member Functions inherited from deep_tau::DeepTauBase
 DeepTauBase (const edm::ParameterSet &cfg, const OutputCollection &outputs, const DeepTauCache *cache)
 
void produce (edm::Event &event, const edm::EventSetup &es) override
 
 ~DeepTauBase () override
 
- Public Member Functions inherited from edm::stream::EDProducer< edm::GlobalCache< DeepTauCache > >
 EDProducer ()=default
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 

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)
 
- Static Public Member Functions inherited from deep_tau::DeepTauBase
static void globalEndJob (const DeepTauCache *cache)
 
static std::unique_ptr< DeepTauCacheinitializeGlobalCache (const edm::ParameterSet &cfg)
 

Static Public Attributes

static float default_value = -999.
 

Private Member Functions

void checkInputs (const tensorflow::Tensor &inputs, const char *block_name, int n_inputs, int n_eta=1, int n_phi=1) const
 
void createConvFeatures (const TauType &tau, const reco::Vertex &pv, double rho, const pat::ElectronCollection &electrons, const pat::MuonCollection &muons, const pat::PackedCandidateCollection &pfCands, const CellGrid &grid, bool is_inner)
 
void createEgammaBlockInputs (const TauType &tau, const reco::Vertex &pv, double rho, const pat::ElectronCollection &electrons, const pat::PackedCandidateCollection &pfCands, const Cell &cell_map, bool is_inner)
 
void createHadronsBlockInputs (const TauType &tau, const reco::Vertex &pv, double rho, const pat::PackedCandidateCollection &pfCands, const Cell &cell_map, bool is_inner)
 
template<typename dnn >
tensorflow::Tensor createInputsV1 (const TauType &tau, const ElectronCollection &electrons, const MuonCollection &muons) const
 
void createMuonBlockInputs (const TauType &tau, const reco::Vertex &pv, double rho, const pat::MuonCollection &muons, const pat::PackedCandidateCollection &pfCands, const Cell &cell_map, bool is_inner)
 
void createTauBlockInputs (const TauType &tau, const reco::Vertex &pv, double rho)
 
template<typename Collection >
void fillGrids (const TauType &tau, const Collection &objects, CellGrid &inner_grid, CellGrid &outer_grid)
 
void getPartialPredictions (tensorflow::Tensor &convTensor, bool is_inner, int eta_index, int phi_index)
 
tensorflow::Tensor getPredictions (edm::Event &event, const edm::EventSetup &es, edm::Handle< TauCollection > taus) override
 
void getPredictionsV1 (const TauType &tau, const pat::ElectronCollection &electrons, const pat::MuonCollection &muons, std::vector< tensorflow::Tensor > &pred_vector)
 
void getPredictionsV2 (const TauType &tau, const pat::ElectronCollection &electrons, const pat::MuonCollection &muons, const pat::PackedCandidateCollection &pfCands, const reco::Vertex &pv, double rho, std::vector< tensorflow::Tensor > &pred_vector)
 
void setCellConvFeatures (tensorflow::Tensor &convTensor, const tensorflow::Tensor &features, 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)
 
static bool calculateGottfriedJacksonAngleDifference (const pat::Tau &tau, double &gj_diff)
 
static float calculateGottfriedJacksonAngleDifference (const pat::Tau &tau)
 
static const pat::ElectronfindMatchedElectron (const pat::Tau &tau, const pat::ElectronCollection &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 isInEcalCrack (double eta)
 
template<typename CandidateCollection >
static void processIsolationPFComponents (const pat::Tau &tau, const CandidateCollection &candidates, LorentzVectorXYZ &p4, float &pt, float &d_eta, float &d_phi, float &m, float &n)
 
template<typename CandidateCollection >
static void processSignalPFComponents (const pat::Tau &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

TauIdMVAAuxiliaries clusterVariables
 
std::array< std::shared_ptr< tensorflow::Tensor >, 2 > convTensor_
 
const int debug_level
 
const bool disable_dxy_pca_
 
std::array< std::shared_ptr< tensorflow::Tensor >, 2 > eGammaTensor_
 
edm::EDGetTokenT< ElectronCollectionelectrons_token_
 
std::array< std::shared_ptr< tensorflow::Tensor >, 2 > hadronsTensor_
 
std::string input_layer_
 
edm::EDGetTokenT< MuonCollectionmuons_token_
 
std::array< std::shared_ptr< tensorflow::Tensor >, 2 > muonTensor_
 
std::string output_layer_
 
edm::EDGetTokenT< double > rho_token_
 
std::shared_ptr< tensorflow::Tensor > tauBlockTensor_
 
const unsigned version
 
std::array< std::shared_ptr< tensorflow::Tensor >, 2 > zeroOutputTensor_
 

Static Private Attributes

static float pi = M_PI
 

Additional Inherited Members

- Public Types inherited from deep_tau::DeepTauBase
using Cutter = 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 = std::vector< TauType >
 
using TauDiscriminator = pat::PATTauDiscriminator
 
using TauRef = edm::Ref< TauCollection >
 
using TauRefProd = edm::RefProd< TauCollection >
 
using TauType = pat::Tau
 
using WPMap = std::map< std::string, CutterPtr >
 
- Public Types inherited from edm::stream::EDProducer< edm::GlobalCache< DeepTauCache > >
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 
- Protected Attributes inherited from deep_tau::DeepTauBase
const DeepTauCachecache_
 
OutputCollection outputs_
 
edm::EDGetTokenT< pat::PackedCandidateCollectionpfcandToken_
 
edm::EDGetTokenT< TauCollectiontausToken_
 
edm::EDGetTokenT< reco::VertexCollectionvtxToken_
 
std::map< std::string, WPMapworkingPoints_
 

Detailed Description

Definition at line 551 of file DeepTauId.cc.

Constructor & Destructor Documentation

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

Definition at line 599 of file DeepTauId.cc.

References Exception, gen::n, dataset::name, and jets_cff::version.

599  :
600  DeepTauBase(cfg, GetOutputs(), cache),
601  electrons_token_(consumes<ElectronCollection>(cfg.getParameter<edm::InputTag>("electrons"))),
602  muons_token_(consumes<MuonCollection>(cfg.getParameter<edm::InputTag>("muons"))),
603  rho_token_(consumes<double>(cfg.getParameter<edm::InputTag>("rho"))),
604  version(cfg.getParameter<unsigned>("version")),
605  debug_level(cfg.getParameter<int>("debug_level")),
606  disable_dxy_pca_(cfg.getParameter<bool>("disable_dxy_pca"))
607  {
608  if(version == 1) {
609  input_layer_ = cache_->getGraph().node(0).name();
610  output_layer_ = cache_->getGraph().node(cache_->getGraph().node_size() - 1).name();
611  const auto& shape = cache_->getGraph().node(0).attr().at("shape").shape();
612  if(shape.dim(1).size() != dnn_inputs_2017v1::NumberOfInputs)
613  throw cms::Exception("DeepTauId") << "number of inputs does not match the expected inputs for the given version";
614  } else if(version == 2) {
615  tauBlockTensor_ = std::make_shared<tensorflow::Tensor>(tensorflow::DT_FLOAT, tensorflow::TensorShape{ 1,
616  dnn_inputs_2017_v2::TauBlockInputs::NumberOfInputs});
617  for(size_t n = 0; n < 2; ++n) {
618  const bool is_inner = n == 0;
619  const auto n_cells = is_inner ? dnn_inputs_2017_v2::number_of_inner_cell
620  : dnn_inputs_2017_v2::number_of_outer_cell;
621  eGammaTensor_[is_inner] = std::make_shared<tensorflow::Tensor>(tensorflow::DT_FLOAT,
622  tensorflow::TensorShape{1, 1, 1, dnn_inputs_2017_v2::EgammaBlockInputs::NumberOfInputs});
623  muonTensor_[is_inner] = std::make_shared<tensorflow::Tensor>(tensorflow::DT_FLOAT,
624  tensorflow::TensorShape{1, 1, 1, dnn_inputs_2017_v2::MuonBlockInputs::NumberOfInputs});
625  hadronsTensor_[is_inner] = std::make_shared<tensorflow::Tensor>(tensorflow::DT_FLOAT,
626  tensorflow::TensorShape{1, 1, 1, dnn_inputs_2017_v2::HadronBlockInputs::NumberOfInputs});
627  convTensor_[is_inner] = std::make_shared<tensorflow::Tensor>(tensorflow::DT_FLOAT,
628  tensorflow::TensorShape{1, n_cells, n_cells, dnn_inputs_2017_v2::number_of_conv_features});
629  zeroOutputTensor_[is_inner] = std::make_shared<tensorflow::Tensor>(tensorflow::DT_FLOAT,
630  tensorflow::TensorShape{1, 1, 1, dnn_inputs_2017_v2::number_of_conv_features});
631 
632 
633  eGammaTensor_[is_inner]->flat<float>().setZero();
634  muonTensor_[is_inner]->flat<float>().setZero();
635  hadronsTensor_[is_inner]->flat<float>().setZero();
636  getPartialPredictions(*zeroOutputTensor_[is_inner], is_inner, 0, 0);
637 
638  }
639  } else {
640  throw cms::Exception("DeepTauId") << "version " << version << " is not supported.";
641  }
642 
643  }
T getParameter(std::string const &) const
edm::EDGetTokenT< ElectronCollection > electrons_token_
Definition: DeepTauId.cc:1696
const bool disable_dxy_pca_
Definition: DeepTauId.cc:1702
const DeepTauCache * cache_
Definition: DeepTauBase.h:103
const tensorflow::GraphDef & getGraph(const std::string &name="") const
Definition: DeepTauBase.h:50
std::array< std::shared_ptr< tensorflow::Tensor >, 2 > muonTensor_
Definition: DeepTauId.cc:1704
static const OutputCollection & GetOutputs()
Definition: DeepTauId.cc:556
std::array< std::shared_ptr< tensorflow::Tensor >, 2 > hadronsTensor_
Definition: DeepTauId.cc:1704
std::string output_layer_
Definition: DeepTauId.cc:1699
std::array< std::shared_ptr< tensorflow::Tensor >, 2 > zeroOutputTensor_
Definition: DeepTauId.cc:1704
std::string input_layer_
Definition: DeepTauId.cc:1699
DeepTauBase(const edm::ParameterSet &cfg, const OutputCollection &outputs, const DeepTauCache *cache)
Definition: DeepTauBase.cc:79
void getPartialPredictions(tensorflow::Tensor &convTensor, bool is_inner, int eta_index, int phi_index)
Definition: DeepTauId.cc:830
std::shared_ptr< tensorflow::Tensor > tauBlockTensor_
Definition: DeepTauId.cc:1703
std::array< std::shared_ptr< tensorflow::Tensor >, 2 > convTensor_
Definition: DeepTauId.cc:1704
const unsigned version
Definition: DeepTauId.cc:1700
std::array< std::shared_ptr< tensorflow::Tensor >, 2 > eGammaTensor_
Definition: DeepTauId.cc:1704
edm::EDGetTokenT< MuonCollection > muons_token_
Definition: DeepTauId.cc:1697
const int debug_level
Definition: DeepTauId.cc:1701
edm::EDGetTokenT< double > rho_token_
Definition: DeepTauId.cc:1698

Member Function Documentation

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

Definition at line 1568 of file DeepTauId.cc.

References pat::Electron::superCluster().

1569  {
1570  if(ele) {
1571  elecEe = elecEgamma = 0;
1572  auto superCluster = ele->superCluster();
1573  if(superCluster.isNonnull() && superCluster.isAvailable() && superCluster->clusters().isNonnull()
1574  && superCluster->clusters().isAvailable()) {
1575  for(auto iter = superCluster->clustersBegin(); iter != superCluster->clustersEnd(); ++iter) {
1576  const double energy = (*iter)->energy();
1577  if(iter == superCluster->clustersBegin()) elecEe += energy;
1578  else elecEgamma += energy;
1579  }
1580  }
1581  } else {
1582  elecEe = elecEgamma = default_value;
1583  }
1584  }
static float default_value
Definition: DeepTauId.cc:554
reco::SuperClusterRef superCluster() const override
override the reco::GsfElectron::superCluster method, to access the internal storage of the superclust...
static bool DeepTauId::calculateElectronClusterVarsV2 ( const pat::Electron ele,
float &  cc_ele_energy,
float &  cc_gamma_energy,
int &  cc_n_gamma 
)
inlinestaticprivate

Definition at line 682 of file DeepTauId.cc.

References pat::Electron::superCluster().

684  {
685  cc_ele_energy = cc_gamma_energy = 0;
686  cc_n_gamma = 0;
687  const auto& superCluster = ele.superCluster();
688  if(superCluster.isNonnull() && superCluster.isAvailable() && superCluster->clusters().isNonnull()
689  && superCluster->clusters().isAvailable()) {
690  for(auto iter = superCluster->clustersBegin(); iter != superCluster->clustersEnd(); ++iter) {
691  const float energy = static_cast<float>((*iter)->energy());
692  if(iter == superCluster->clustersBegin())
693  cc_ele_energy += energy;
694  else {
695  cc_gamma_energy += energy;
696  ++cc_n_gamma;
697  }
698  }
699  return true;
700  } else
701  return false;
702  }
reco::SuperClusterRef superCluster() const override
override the reco::GsfElectron::superCluster method, to access the internal storage of the superclust...
static bool DeepTauId::calculateGottfriedJacksonAngleDifference ( const pat::Tau tau,
double &  gj_diff 
)
inlinestaticprivate

Definition at line 1649 of file DeepTauId.cc.

References funct::abs(), constexpr, pat::Tau::flightLength(), pat::Tau::hasSecondaryVertex(), reco::LeafCandidate::p(), reco::LeafCandidate::p4(), and funct::pow().

1650  {
1651  if(tau.hasSecondaryVertex()) {
1652  static constexpr double mTau = 1.77682;
1653  const double mAOne = tau.p4().M();
1654  const double pAOneMag = tau.p();
1655  const double argumentThetaGJmax = (std::pow(mTau,2) - std::pow(mAOne,2) ) / ( 2 * mTau * pAOneMag );
1656  const double argumentThetaGJmeasured = tau.p4().Vect().Dot(tau.flightLength())
1657  / ( pAOneMag * tau.flightLength().R() );
1658  if ( std::abs(argumentThetaGJmax) <= 1. && std::abs(argumentThetaGJmeasured) <= 1. ) {
1659  double thetaGJmax = std::asin( argumentThetaGJmax );
1660  double thetaGJmeasured = std::acos( argumentThetaGJmeasured );
1661  gj_diff = thetaGJmeasured - thetaGJmax;
1662  return true;
1663  }
1664  }
1665  return false;
1666  }
#define constexpr
const pat::tau::TauPFEssential::Vector & flightLength() const
Definition: Tau.h:321
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const LorentzVector & p4() const final
four-momentum Lorentz vector
Definition: LeafCandidate.h:99
bool hasSecondaryVertex() const
Definition: Tau.h:320
double p() const final
magnitude of momentum vector
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
static float DeepTauId::calculateGottfriedJacksonAngleDifference ( const pat::Tau tau)
inlinestaticprivate

Definition at line 1668 of file DeepTauId.cc.

1669  {
1670  double gj_diff;
1672  return static_cast<float>(gj_diff);
1673  return default_value;
1674  }
static bool calculateGottfriedJacksonAngleDifference(const pat::Tau &tau, double &gj_diff)
Definition: DeepTauId.cc:1649
static float default_value
Definition: DeepTauId.cc:554
void DeepTauId::checkInputs ( const tensorflow::Tensor &  inputs,
const char *  block_name,
int  n_inputs,
int  n_eta = 1,
int  n_phi = 1 
) const
inlineprivate

Definition at line 704 of file DeepTauId.cc.

References gather_cfg::cout, PVValHelper::eta, Exception, alignBH_cfg::fixed, objects.autophobj::float, input, edm::isNotFinite(), and gen::k.

706  {
707  if(debug_level >= 1){
708  for(int eta = 0; eta < n_eta; ++eta){
709  for(int phi = 0; phi < n_phi; phi++){
710  for(int k = 0; k < n_inputs; ++k) {
711  const float input = n_eta == 1 && n_phi == 1
712  ? inputs.matrix<float>()(0, k) : inputs.tensor<float,4>()(0, eta, phi, k);
713  if(edm::isNotFinite(input))
714  throw cms::Exception("DeepTauId") << "in the " << block_name << ", input is not finite, i.e. infinite or NaN, for eta_index = "
715  << n_eta << ", phi_index = " << n_phi << ", input_index = " << k;
716  if(debug_level >= 2)
717  std::cout << block_name << "," << eta << ","<< phi << "," << k << "," << std::setprecision(5) << std::fixed << input << '\n';
718  }
719  }
720  }
721  }
722  }
static std::string const input
Definition: EdmProvDump.cc:44
bool isNotFinite(T x)
Definition: isFinite.h:10
int k[5][pyjets_maxn]
const int debug_level
Definition: DeepTauId.cc:1701
void DeepTauId::createConvFeatures ( const TauType tau,
const reco::Vertex pv,
double  rho,
const pat::ElectronCollection electrons,
const pat::MuonCollection muons,
const pat::PackedCandidateCollection pfCands,
const CellGrid &  grid,
bool  is_inner 
)
inlineprivate

Definition at line 849 of file DeepTauId.cc.

References PVValHelper::eta.

852  {
853  tensorflow::Tensor& convTensor = *convTensor_.at(is_inner);
854  for(int eta = -grid.maxEtaIndex(); eta <= grid.maxEtaIndex(); ++eta) {
855  for(int phi = -grid.maxPhiIndex(); phi <= grid.maxPhiIndex(); ++phi) {
856  const CellIndex cell_index{eta, phi};
857  const int eta_index = grid.getEtaTensorIndex(cell_index);
858  const int phi_index = grid.getPhiTensorIndex(cell_index);
859 
860  const auto cell_iter = grid.find(cell_index);
861  if(cell_iter != grid.end()) {
862  const Cell& cell = cell_iter->second;
863  createEgammaBlockInputs(tau, pv, rho, electrons, pfCands, cell, is_inner);
864  createMuonBlockInputs(tau, pv, rho, muons, pfCands, cell, is_inner);
865  createHadronsBlockInputs(tau, pv, rho, pfCands, cell, is_inner);
866  getPartialPredictions(convTensor, is_inner, eta_index, phi_index);
867  } else {
868  setCellConvFeatures(convTensor, *zeroOutputTensor_[is_inner], eta_index, phi_index);
869  }
870  }
871  }
872  }
void createHadronsBlockInputs(const TauType &tau, const reco::Vertex &pv, double rho, const pat::PackedCandidateCollection &pfCands, const Cell &cell_map, bool is_inner)
Definition: DeepTauId.cc:1284
std::array< std::shared_ptr< tensorflow::Tensor >, 2 > zeroOutputTensor_
Definition: DeepTauId.cc:1704
void getPartialPredictions(tensorflow::Tensor &convTensor, bool is_inner, int eta_index, int phi_index)
Definition: DeepTauId.cc:830
std::array< std::shared_ptr< tensorflow::Tensor >, 2 > convTensor_
Definition: DeepTauId.cc:1704
void createEgammaBlockInputs(const TauType &tau, const reco::Vertex &pv, double rho, const pat::ElectronCollection &electrons, const pat::PackedCandidateCollection &pfCands, const Cell &cell_map, bool is_inner)
Definition: DeepTauId.cc:976
void setCellConvFeatures(tensorflow::Tensor &convTensor, const tensorflow::Tensor &features, int eta_index, int phi_index)
Definition: DeepTauId.cc:874
void createMuonBlockInputs(const TauType &tau, const reco::Vertex &pv, double rho, const pat::MuonCollection &muons, const pat::PackedCandidateCollection &pfCands, const Cell &cell_map, bool is_inner)
Definition: DeepTauId.cc:1156
void DeepTauId::createEgammaBlockInputs ( const TauType tau,
const reco::Vertex pv,
double  rho,
const pat::ElectronCollection electrons,
const pat::PackedCandidateCollection pfCands,
const Cell &  cell_map,
bool  is_inner 
)
inlineprivate

Definition at line 976 of file DeepTauId.cc.

References funct::abs(), particleFlow_cfi::dPhi, nanoDQM_cff::Electron, f, pat::Tau::flightLength(), objects.autophobj::float, reco::JetExtendedAssociation::getValue(), PatBasicFWLiteJetAnalyzer_Selector_cfg::inputs, reco::LeafCandidate::polarP4(), reco::Vertex::position(), runTauDisplay::tau_eta, and runTauDisplay::tau_pt.

980  {
982 
983  tensorflow::Tensor& inputs = *eGammaTensor_.at(is_inner);
984  inputs.flat<float>().setZero();
985 
986  const auto& get = [&](int var_index) -> float& {
987  return inputs.tensor<float,4>()(0, 0, 0, var_index);
988  };
989 
990  const bool valid_index_pf_ele = cell_map.count(CellObjectType::PfCand_electron);
991  const bool valid_index_pf_gamma = cell_map.count(CellObjectType::PfCand_gamma);
992  const bool valid_index_ele = cell_map.count(CellObjectType::Electron);
993 
994  if(!cell_map.empty()){
995  get(dnn::rho) = getValueNorm(rho, 21.49f, 9.713f);
996  get(dnn::tau_pt) = getValueLinear(tau.polarP4().pt(), 20.f, 1000.f, true);
997  get(dnn::tau_eta) = getValueLinear(tau.polarP4().eta(), -2.3f, 2.3f, false);
998  get(dnn::tau_inside_ecal_crack) = getValue(isInEcalCrack(tau.polarP4().eta()));
999  }
1000  if(valid_index_pf_ele){
1001  size_t index_pf_ele = cell_map.at(CellObjectType::PfCand_electron);
1002 
1003  get(dnn::pfCand_ele_valid) = valid_index_pf_ele;
1004  get(dnn::pfCand_ele_rel_pt) = getValueNorm(pfCands.at(index_pf_ele).polarP4().pt() / tau.polarP4().pt(),
1005  is_inner ? 0.9792f : 0.304f, is_inner ? 0.5383f : 1.845f);
1006  get(dnn::pfCand_ele_deta) = getValueLinear(pfCands.at(index_pf_ele).polarP4().eta() - tau.polarP4().eta(),
1007  is_inner ? -0.1f : -0.5f, is_inner ? 0.1f : 0.5f, false);
1008  get(dnn::pfCand_ele_dphi) = getValueLinear(dPhi(tau.polarP4(), pfCands.at(index_pf_ele).polarP4()),
1009  is_inner ? -0.1f : -0.5f, is_inner ? 0.1f : 0.5f, false);
1010  get(dnn::pfCand_ele_pvAssociationQuality) = getValueLinear<int>(pfCands.at(index_pf_ele).pvAssociationQuality(), 0, 7, true);
1011  get(dnn::pfCand_ele_puppiWeight) = getValue(pfCands.at(index_pf_ele).puppiWeight());
1012  get(dnn::pfCand_ele_charge) = getValue(pfCands.at(index_pf_ele).charge());
1013  get(dnn::pfCand_ele_lostInnerHits) = getValue<int>(pfCands.at(index_pf_ele).lostInnerHits());
1014  get(dnn::pfCand_ele_numberOfPixelHits) = getValueLinear(pfCands.at(index_pf_ele).numberOfPixelHits(), 0, 10, true);
1015  get(dnn::pfCand_ele_vertex_dx) = getValueNorm(pfCands.at(index_pf_ele).vertex().x() - pv.position().x(), 0.f, 0.1221f);
1016  get(dnn::pfCand_ele_vertex_dy) = getValueNorm(pfCands.at(index_pf_ele).vertex().y() - pv.position().y(), 0.f, 0.1226f);
1017  get(dnn::pfCand_ele_vertex_dz) = getValueNorm(pfCands.at(index_pf_ele).vertex().z() - pv.position().z(), 0.001f, 1.024f);
1018  get(dnn::pfCand_ele_vertex_dx_tauFL) = getValueNorm(pfCands.at(index_pf_ele).vertex().x() -
1019  pv.position().x() - tau.flightLength().x(), 0.f, 0.3411f);
1020  get(dnn::pfCand_ele_vertex_dy_tauFL) = getValueNorm(pfCands.at(index_pf_ele).vertex().y() -
1021  pv.position().y() - tau.flightLength().y(), 0.0003f, 0.3385f);
1022  get(dnn::pfCand_ele_vertex_dz_tauFL) = getValueNorm(pfCands.at(index_pf_ele).vertex().z() -
1023  pv.position().z() - tau.flightLength().z(), 0.f, 1.307f);
1024 
1025  const bool hasTrackDetails = pfCands.at(index_pf_ele).hasTrackDetails();
1026  if(hasTrackDetails){
1027  get(dnn::pfCand_ele_hasTrackDetails) = hasTrackDetails;
1028  get(dnn::pfCand_ele_dxy) = getValueNorm(pfCands.at(index_pf_ele).dxy(), 0.f, 0.171f);
1029  get(dnn::pfCand_ele_dxy_sig) = getValueNorm(std::abs(pfCands.at(index_pf_ele).dxy()) /
1030  pfCands.at(index_pf_ele).dxyError(), 1.634f, 6.45f);
1031  get(dnn::pfCand_ele_dz) = getValueNorm(pfCands.at(index_pf_ele).dz(), 0.001f, 1.02f);
1032  get(dnn::pfCand_ele_dz_sig) = getValueNorm(std::abs(pfCands.at(index_pf_ele).dz()) /
1033  pfCands.at(index_pf_ele).dzError(), 24.56f, 210.4f);
1034  get(dnn::pfCand_ele_track_chi2_ndof) = getValueNorm(pfCands.at(index_pf_ele).pseudoTrack().chi2() /
1035  pfCands.at(index_pf_ele).pseudoTrack().ndof(), 2.272f, 8.439f);
1036  get(dnn::pfCand_ele_track_ndof) = getValueNorm(pfCands.at(index_pf_ele).pseudoTrack().ndof(), 15.18f, 3.203f);
1037  }
1038  }
1039  if(valid_index_pf_gamma){
1040  size_t index_pf_gamma = cell_map.at(CellObjectType::PfCand_gamma);
1041  get(dnn::pfCand_gamma_valid) = valid_index_pf_gamma;
1042  get(dnn::pfCand_gamma_rel_pt) = getValueNorm(pfCands.at(index_pf_gamma).polarP4().pt() / tau.polarP4().pt(),
1043  is_inner ? 0.6048f : 0.02576f, is_inner ? 1.669f : 0.3833f);
1044  get(dnn::pfCand_gamma_deta) = getValueLinear(pfCands.at(index_pf_gamma).polarP4().eta() - tau.polarP4().eta(),
1045  is_inner ? -0.1f : -0.5f, is_inner ? 0.1f : 0.5f, false);
1046  get(dnn::pfCand_gamma_dphi) = getValueLinear(dPhi(tau.polarP4(), pfCands.at(index_pf_gamma).polarP4()),
1047  is_inner ? -0.1f : -0.5f, is_inner ? 0.1f : 0.5f, false);
1048  get(dnn::pfCand_gamma_pvAssociationQuality) =
1049  getValueLinear<int>(pfCands.at(index_pf_gamma).pvAssociationQuality(), 0, 7, true);
1050  get(dnn::pfCand_gamma_fromPV) = getValueLinear<int>(pfCands.at(index_pf_gamma).fromPV(), 0, 3, true);
1051  get(dnn::pfCand_gamma_puppiWeight) = getValue(pfCands.at(index_pf_gamma).puppiWeight());
1052  get(dnn::pfCand_gamma_puppiWeightNoLep) = getValue(pfCands.at(index_pf_gamma).puppiWeightNoLep());
1053  get(dnn::pfCand_gamma_lostInnerHits) = getValue<int>(pfCands.at(index_pf_gamma).lostInnerHits());
1054  get(dnn::pfCand_gamma_numberOfPixelHits) = getValueLinear(pfCands.at(index_pf_gamma).numberOfPixelHits(), 0, 7, true);
1055  get(dnn::pfCand_gamma_vertex_dx) = getValueNorm(pfCands.at(index_pf_gamma).vertex().x() - pv.position().x(), 0.f, 0.0067f);
1056  get(dnn::pfCand_gamma_vertex_dy) = getValueNorm(pfCands.at(index_pf_gamma).vertex().y() - pv.position().y(), 0.f, 0.0069f);
1057  get(dnn::pfCand_gamma_vertex_dz) = getValueNorm(pfCands.at(index_pf_gamma).vertex().z() - pv.position().z(), 0.f, 0.0578f);
1058  get(dnn::pfCand_gamma_vertex_dx_tauFL) = getValueNorm(pfCands.at(index_pf_gamma).vertex().x() -
1059  pv.position().x() - tau.flightLength().x(), 0.001f, 0.9565f);
1060  get(dnn::pfCand_gamma_vertex_dy_tauFL) = getValueNorm(pfCands.at(index_pf_gamma).vertex().y() -
1061  pv.position().y() - tau.flightLength().y(), 0.0008f, 0.9592f);
1062  get(dnn::pfCand_gamma_vertex_dz_tauFL) = getValueNorm(pfCands.at(index_pf_gamma).vertex().z() -
1063  pv.position().z() - tau.flightLength().z(), 0.0038f, 2.154f);
1064 
1065  const bool hasTrackDetails = pfCands.at(index_pf_gamma).hasTrackDetails();
1066  if(hasTrackDetails){
1067  get(dnn::pfCand_gamma_hasTrackDetails) = hasTrackDetails;
1068  get(dnn::pfCand_gamma_dxy) = getValueNorm(pfCands.at(index_pf_gamma).dxy(), 0.0004f, 0.882f);
1069  get(dnn::pfCand_gamma_dxy_sig) = getValueNorm(std::abs(pfCands.at(index_pf_gamma).dxy()) /
1070  pfCands.at(index_pf_gamma).dxyError(), 4.271f, 63.78f);
1071  get(dnn::pfCand_gamma_dz) = getValueNorm(pfCands.at(index_pf_gamma).dz(), 0.0071f, 5.285f);
1072  get(dnn::pfCand_gamma_dz_sig) = getValueNorm(std::abs(pfCands.at(index_pf_gamma).dz()) /
1073  pfCands.at(index_pf_gamma).dzError(), 162.1f, 622.4f);
1074  get(dnn::pfCand_gamma_track_chi2_ndof) = pfCands.at(index_pf_gamma).pseudoTrack().ndof() > 0 ?
1075  getValueNorm(pfCands.at(index_pf_gamma).pseudoTrack().chi2() /
1076  pfCands.at(index_pf_gamma).pseudoTrack().ndof(), 4.268f, 15.47f) : 0;
1077  get(dnn::pfCand_gamma_track_ndof) = pfCands.at(index_pf_gamma).pseudoTrack().ndof() > 0 ?
1078  getValueNorm(pfCands.at(index_pf_gamma).pseudoTrack().ndof(), 12.25f, 4.774f) : 0;
1079  }
1080  }
1081  if(valid_index_ele){
1082  size_t index_ele = cell_map.at(CellObjectType::Electron);
1083 
1084  get(dnn::ele_valid) = valid_index_ele;
1085  get(dnn::ele_rel_pt) = getValueNorm(electrons.at(index_ele).polarP4().pt() / tau.polarP4().pt(),
1086  is_inner ? 1.067f : 0.5111f, is_inner ? 1.521f : 2.765f);
1087  get(dnn::ele_deta) = getValueLinear(electrons.at(index_ele).polarP4().eta() - tau.polarP4().eta(),
1088  is_inner ? -0.1f : -0.5f, is_inner ? 0.1f : 0.5f, false);
1089  get(dnn::ele_dphi) = getValueLinear(dPhi(tau.polarP4(), electrons.at(index_ele).polarP4()),
1090  is_inner ? -0.1f : -0.5f, is_inner ? 0.1f : 0.5f, false);
1091 
1092  float cc_ele_energy, cc_gamma_energy;
1093  int cc_n_gamma;
1094  const bool cc_valid = calculateElectronClusterVarsV2(electrons.at(index_ele), cc_ele_energy, cc_gamma_energy, cc_n_gamma);
1095  if(cc_valid){
1096  get(dnn::ele_cc_valid) = cc_valid;
1097  get(dnn::ele_cc_ele_rel_energy) = getValueNorm(cc_ele_energy / electrons.at(index_ele).polarP4().pt(), 1.729f, 1.644f);
1098  get(dnn::ele_cc_gamma_rel_energy) = getValueNorm(cc_gamma_energy / cc_ele_energy, 0.1439f, 0.3284f);
1099  get(dnn::ele_cc_n_gamma) = getValueNorm(cc_n_gamma, 1.794f, 2.079f);
1100  }
1101  get(dnn::ele_rel_trackMomentumAtVtx) = getValueNorm(electrons.at(index_ele).trackMomentumAtVtx().R() /
1102  electrons.at(index_ele).polarP4().pt(), 1.531f, 1.424f);
1103  get(dnn::ele_rel_trackMomentumAtCalo) = getValueNorm(electrons.at(index_ele).trackMomentumAtCalo().R() /
1104  electrons.at(index_ele).polarP4().pt(), 1.531f, 1.424f);
1105  get(dnn::ele_rel_trackMomentumOut) = getValueNorm(electrons.at(index_ele).trackMomentumOut().R() /
1106  electrons.at(index_ele).polarP4().pt(), 0.7735f, 0.935f);
1107  get(dnn::ele_rel_trackMomentumAtEleClus) = getValueNorm(electrons.at(index_ele).trackMomentumAtEleClus().R() /
1108  electrons.at(index_ele).polarP4().pt(), 0.7735f, 0.935f);
1109  get(dnn::ele_rel_trackMomentumAtVtxWithConstraint) =
1110  getValueNorm(electrons.at(index_ele).trackMomentumAtVtxWithConstraint().R() /
1111  electrons.at(index_ele).polarP4().pt(), 1.625f, 1.581f);
1112  get(dnn::ele_rel_ecalEnergy) = getValueNorm(electrons.at(index_ele).ecalEnergy() /
1113  electrons.at(index_ele).polarP4().pt(), 1.993f, 1.308f);
1114  get(dnn::ele_ecalEnergy_sig) = getValueNorm(electrons.at(index_ele).ecalEnergy() /
1115  electrons.at(index_ele).ecalEnergyError(), 70.25f, 58.16f);
1116  get(dnn::ele_eSuperClusterOverP) = getValueNorm(electrons.at(index_ele).eSuperClusterOverP(), 2.432f, 15.13f);
1117  get(dnn::ele_eSeedClusterOverP) = getValueNorm(electrons.at(index_ele).eSeedClusterOverP(), 2.034f, 13.96f);
1118  get(dnn::ele_eSeedClusterOverPout) = getValueNorm(electrons.at(index_ele).eSeedClusterOverPout(), 6.64f, 36.8f);
1119  get(dnn::ele_eEleClusterOverPout) = getValueNorm(electrons.at(index_ele).eEleClusterOverPout(), 4.183f, 20.63f);
1120  get(dnn::ele_deltaEtaSuperClusterTrackAtVtx) =
1121  getValueNorm(electrons.at(index_ele).deltaEtaSuperClusterTrackAtVtx(),0.f, 0.0363f);
1122  get(dnn::ele_deltaEtaSeedClusterTrackAtCalo) =
1123  getValueNorm(electrons.at(index_ele).deltaEtaSeedClusterTrackAtCalo(), -0.0001f, 0.0512f);
1124  get(dnn::ele_deltaEtaEleClusterTrackAtCalo) =
1125  getValueNorm(electrons.at(index_ele).deltaEtaEleClusterTrackAtCalo(), -0.0001f, 0.0541f);
1126  get(dnn::ele_deltaPhiEleClusterTrackAtCalo) =
1127  getValueNorm(electrons.at(index_ele).deltaPhiEleClusterTrackAtCalo(), 0.0002f, 0.0553f);
1128  get(dnn::ele_deltaPhiSuperClusterTrackAtVtx) =
1129  getValueNorm(electrons.at(index_ele).deltaPhiSuperClusterTrackAtVtx(), 0.0001f, 0.0523f);
1130  get(dnn::ele_deltaPhiSeedClusterTrackAtCalo) =
1131  getValueNorm(electrons.at(index_ele).deltaPhiSeedClusterTrackAtCalo(), 0.0004f, 0.0777f);
1132  get(dnn::ele_mvaInput_earlyBrem) = getValue(electrons.at(index_ele).mvaInput().earlyBrem);
1133  get(dnn::ele_mvaInput_lateBrem) = getValue(electrons.at(index_ele).mvaInput().lateBrem);
1134  get(dnn::ele_mvaInput_sigmaEtaEta) = getValueNorm(electrons.at(index_ele).mvaInput().sigmaEtaEta,0.0008f, 0.0052f);
1135  get(dnn::ele_mvaInput_hadEnergy) = getValueNorm(electrons.at(index_ele).mvaInput().hadEnergy, 14.04f, 69.48f);
1136  get(dnn::ele_mvaInput_deltaEta) = getValueNorm(electrons.at(index_ele).mvaInput().deltaEta, 0.0099f, 0.0851f);
1137 
1138  const auto& gsfTrack = electrons.at(index_ele).gsfTrack();
1139  if(gsfTrack.isNonnull()){
1140  get(dnn::ele_gsfTrack_normalizedChi2) = getValueNorm(gsfTrack->normalizedChi2(), 3.049f, 10.39f);
1141  get(dnn::ele_gsfTrack_numberOfValidHits) = getValueNorm(gsfTrack->numberOfValidHits(), 16.52f, 2.806f);
1142  get(dnn::ele_rel_gsfTrack_pt) = getValueNorm(gsfTrack->pt() / electrons.at(index_ele).polarP4().pt(), 1.355f, 16.81f);
1143  get(dnn::ele_gsfTrack_pt_sig) = getValueNorm(gsfTrack->pt() / gsfTrack->ptError(), 5.046f, 3.119f);
1144  }
1145  const auto& closestCtfTrack = electrons.at(index_ele).closestCtfTrackRef();
1146  const bool has_closestCtfTrack = closestCtfTrack.isNonnull();
1147  if(has_closestCtfTrack){
1148  get(dnn::ele_has_closestCtfTrack) = has_closestCtfTrack;
1149  get(dnn::ele_closestCtfTrack_normalizedChi2) = getValueNorm(closestCtfTrack->normalizedChi2(), 2.411f, 6.98f);
1150  get(dnn::ele_closestCtfTrack_numberOfValidHits) = getValueNorm(closestCtfTrack->numberOfValidHits(), 15.16f, 5.26f);
1151  }
1152  }
1153  checkInputs(inputs, is_inner ? "egamma_inner_block" : "egamma_outer_block", dnn::NumberOfInputs);
1154  }
static float getValueLinear(T value, float min_value, float max_value, bool positive)
Definition: DeepTauId.cc:664
static bool isInEcalCrack(double eta)
Definition: DeepTauId.cc:1676
const Point & position() const
position
Definition: Vertex.h:109
static float getValue(T value)
Definition: DeepTauId.cc:658
static float getValueNorm(T value, float mean, float sigma, float n_sigmas_max=5)
Definition: DeepTauId.cc:675
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
std::array< std::shared_ptr< tensorflow::Tensor >, 2 > eGammaTensor_
Definition: DeepTauId.cc:1704
void checkInputs(const tensorflow::Tensor &inputs, const char *block_name, int n_inputs, int n_eta=1, int n_phi=1) const
Definition: DeepTauId.cc:704
static bool calculateElectronClusterVarsV2(const pat::Electron &ele, float &cc_ele_energy, float &cc_gamma_energy, int &cc_n_gamma)
Definition: DeepTauId.cc:682
void DeepTauId::createHadronsBlockInputs ( const TauType tau,
const reco::Vertex pv,
double  rho,
const pat::PackedCandidateCollection pfCands,
const Cell &  cell_map,
bool  is_inner 
)
inlineprivate

Definition at line 1284 of file DeepTauId.cc.

References funct::abs(), particleFlow_cfi::dPhi, f, pat::Tau::flightLength(), objects.autophobj::float, edm::Ptr< T >::get(), reco::JetExtendedAssociation::getValue(), PatBasicFWLiteJetAnalyzer_Selector_cfg::inputs, pat::Tau::leadChargedHadrCand(), reco::LeafCandidate::polarP4(), reco::Vertex::position(), runTauDisplay::tau_eta, and runTauDisplay::tau_pt.

1287  {
1288  namespace dnn = dnn_inputs_2017_v2::HadronBlockInputs;
1289 
1290  tensorflow::Tensor& inputs = *hadronsTensor_.at(is_inner);
1291  inputs.flat<float>().setZero();
1292 
1293 
1294  const auto& get = [&](int var_index) -> float& {
1295  return inputs.tensor<float,4>()(0, 0, 0, var_index);
1296  };
1297 
1298  const bool valid_chH = cell_map.count(CellObjectType::PfCand_chargedHadron);
1299  const bool valid_nH = cell_map.count(CellObjectType::PfCand_neutralHadron);
1300 
1301  if(!cell_map.empty()){
1302  get(dnn::rho) = getValueNorm(rho, 21.49f, 9.713f);
1303  get(dnn::tau_pt) = getValueLinear(tau.polarP4().pt(), 20.f, 1000.f, true);
1304  get(dnn::tau_eta) = getValueLinear(tau.polarP4().eta(), -2.3f, 2.3f, false);
1305  get(dnn::tau_inside_ecal_crack) = getValue(isInEcalCrack(tau.polarP4().eta()));
1306  }
1307  if(valid_chH){
1308  size_t index_chH = cell_map.at(CellObjectType::PfCand_chargedHadron);
1309 
1310  get(dnn::pfCand_chHad_valid) = valid_chH;
1311  get(dnn::pfCand_chHad_rel_pt) = getValueNorm(pfCands.at(index_chH).polarP4().pt() / tau.polarP4().pt(),
1312  is_inner ? 0.2564f : 0.0194f, is_inner ? 0.8607f : 0.1865f);
1313  get(dnn::pfCand_chHad_deta) = getValueLinear(pfCands.at(index_chH).polarP4().eta() - tau.polarP4().eta(),
1314  is_inner ? -0.1f : -0.5f, is_inner ? 0.1f : 0.5f, false);
1315  get(dnn::pfCand_chHad_dphi) = getValueLinear(dPhi(tau.polarP4(),pfCands.at(index_chH).polarP4()),
1316  is_inner ? -0.1f : -0.5f, is_inner ? 0.1f : 0.5f, false);
1317  get(dnn::pfCand_chHad_leadChargedHadrCand) = getValue(&pfCands.at(index_chH) ==
1318  dynamic_cast<const pat::PackedCandidate*>(tau.leadChargedHadrCand().get()));
1319  get(dnn::pfCand_chHad_pvAssociationQuality) =
1320  getValueLinear<int>(pfCands.at(index_chH).pvAssociationQuality(), 0, 7, true);
1321  get(dnn::pfCand_chHad_fromPV) = getValueLinear<int>(pfCands.at(index_chH).fromPV(), 0, 3, true);
1322  get(dnn::pfCand_chHad_puppiWeight) = getValue(pfCands.at(index_chH).puppiWeight());
1323  get(dnn::pfCand_chHad_puppiWeightNoLep) = getValue(pfCands.at(index_chH).puppiWeightNoLep());
1324  get(dnn::pfCand_chHad_charge) = getValue(pfCands.at(index_chH).charge());
1325  get(dnn::pfCand_chHad_lostInnerHits) = getValue<int>(pfCands.at(index_chH).lostInnerHits());
1326  get(dnn::pfCand_chHad_numberOfPixelHits) = getValueLinear(pfCands.at(index_chH).numberOfPixelHits(), 0, 12, true);
1327  get(dnn::pfCand_chHad_vertex_dx) = getValueNorm(pfCands.at(index_chH).vertex().x() - pv.position().x(), 0.0005f, 1.735f);
1328  get(dnn::pfCand_chHad_vertex_dy) = getValueNorm(pfCands.at(index_chH).vertex().y() - pv.position().y(), -0.0008f, 1.752f);
1329  get(dnn::pfCand_chHad_vertex_dz) = getValueNorm(pfCands.at(index_chH).vertex().z() - pv.position().z(), -0.0201f, 8.333f);
1330  get(dnn::pfCand_chHad_vertex_dx_tauFL) = getValueNorm(pfCands.at(index_chH).vertex().x() - pv.position().x()
1331  - tau.flightLength().x(), -0.0014f, 1.93f);
1332  get(dnn::pfCand_chHad_vertex_dy_tauFL) = getValueNorm(pfCands.at(index_chH).vertex().y() - pv.position().y()
1333  - tau.flightLength().y(), 0.0022f, 1.948f);
1334  get(dnn::pfCand_chHad_vertex_dz_tauFL) = getValueNorm(pfCands.at(index_chH).vertex().z() - pv.position().z()
1335  - tau.flightLength().z(), -0.0138f, 8.622f);
1336 
1337  const bool hasTrackDetails = pfCands.at(index_chH).hasTrackDetails();
1338  if(hasTrackDetails){
1339  get(dnn::pfCand_chHad_hasTrackDetails) = hasTrackDetails;
1340  get(dnn::pfCand_chHad_dxy) = getValueNorm(pfCands.at(index_chH).dxy(), -0.012f, 2.386f);
1341  get(dnn::pfCand_chHad_dxy_sig) = getValueNorm(std::abs(pfCands.at(index_chH).dxy()) /
1342  pfCands.at(index_chH).dxyError(), 6.417f, 36.28f);
1343  get(dnn::pfCand_chHad_dz) = getValueNorm(pfCands.at(index_chH).dz(), -0.0246f, 7.618f);
1344  get(dnn::pfCand_chHad_dz_sig) = getValueNorm(std::abs(pfCands.at(index_chH).dz()) /
1345  pfCands.at(index_chH).dzError(), 301.3f, 491.1f);
1346  get(dnn::pfCand_chHad_track_chi2_ndof) = pfCands.at(index_chH).pseudoTrack().ndof() > 0 ?
1347  getValueNorm(pfCands.at(index_chH).pseudoTrack().chi2() /
1348  pfCands.at(index_chH).pseudoTrack().ndof(), 0.7876f, 3.694f) : 0;
1349  get(dnn::pfCand_chHad_track_ndof) = pfCands.at(index_chH).pseudoTrack().ndof() > 0 ?
1350  getValueNorm(pfCands.at(index_chH).pseudoTrack().ndof(), 13.92f, 6.581f) : 0;
1351  }
1352  get(dnn::pfCand_chHad_hcalFraction) = getValue(pfCands.at(index_chH).hcalFraction());
1353  get(dnn::pfCand_chHad_rawCaloFraction) = getValueLinear(pfCands.at(index_chH).rawCaloFraction(), 0.f, 2.6f, true);
1354  }
1355  if(valid_nH){
1356  size_t index_nH = cell_map.at(CellObjectType::PfCand_neutralHadron);
1357 
1358  get(dnn::pfCand_nHad_valid) = valid_nH;
1359  get(dnn::pfCand_nHad_rel_pt) = getValueNorm(pfCands.at(index_nH).polarP4().pt() / tau.polarP4().pt(),
1360  is_inner ? 0.3163f : 0.0502f, is_inner ? 0.2769f : 0.4266f);
1361  get(dnn::pfCand_nHad_deta) = getValueLinear(pfCands.at(index_nH).polarP4().eta() - tau.polarP4().eta(),
1362  is_inner ? -0.1f : -0.5f, is_inner ? 0.1f : 0.5f, false);
1363  get(dnn::pfCand_nHad_dphi) = getValueLinear(dPhi(tau.polarP4(),pfCands.at(index_nH).polarP4()),
1364  is_inner ? -0.1f : -0.5f, is_inner ? 0.1f : 0.5f, false);
1365  get(dnn::pfCand_nHad_puppiWeight) = getValue(pfCands.at(index_nH).puppiWeight());
1366  get(dnn::pfCand_nHad_puppiWeightNoLep) = getValue(pfCands.at(index_nH).puppiWeightNoLep());
1367  get(dnn::pfCand_nHad_hcalFraction) = getValue(pfCands.at(index_nH).hcalFraction());
1368  }
1369  checkInputs(inputs, is_inner ? "hadron_inner_block" : "hadron_outer_block", dnn::NumberOfInputs);
1370  }
static float getValueLinear(T value, float min_value, float max_value, bool positive)
Definition: DeepTauId.cc:664
static bool isInEcalCrack(double eta)
Definition: DeepTauId.cc:1676
const Point & position() const
position
Definition: Vertex.h:109
std::array< std::shared_ptr< tensorflow::Tensor >, 2 > hadronsTensor_
Definition: DeepTauId.cc:1704
static float getValue(T value)
Definition: DeepTauId.cc:658
static float getValueNorm(T value, float mean, float sigma, float n_sigmas_max=5)
Definition: DeepTauId.cc:675
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
void checkInputs(const tensorflow::Tensor &inputs, const char *block_name, int n_inputs, int n_eta=1, int n_phi=1) const
Definition: DeepTauId.cc:704
template<typename dnn >
tensorflow::Tensor DeepTauId::createInputsV1 ( const TauType tau,
const ElectronCollection electrons,
const MuonCollection muons 
) const
inlineprivate

Definition at line 1373 of file DeepTauId.cc.

References funct::abs(), tauProducer_cfi::chargedIsoPtSum, constexpr, taus_cff::decayMode, pat::Tau::decayMode(), particleFlow_cfi::dEta, particleFlow_cfi::dPhi, PVValHelper::dxy, pat::Tau::dxy(), pat::Tau::dxy_Sig(), PVValHelper::dz, pat::Tau::ecalEnergyLeadChargedHadrCand(), pat::Tau::emFraction_MVA(), PVValHelper::eta, pat::Tau::etaAtEcalEntranceLeadChargedCand(), Exception, pat::Tau::flightLength(), pat::Tau::flightLengthSig(), edm::Ptr< T >::get(), pat::Tau::hasSecondaryVertex(), pat::Tau::hcalEnergyLeadChargedHadrCand(), PatBasicFWLiteJetAnalyzer_Selector_cfg::inputs, electrons_cff::ip3d, pat::Tau::ip3d(), pat::Tau::ip3d_Sig(), edm::Ptr< T >::isNonnull(), pat::Tau::leadChargedHadrCand(), pat::Tau::leadingTrackNormChi2(), pat::Tau::leadPFChargedHadrCand(), ResonanceBuilder::mass, tauProducer_cfi::neutralIsoPtSum, tauProducer_cfi::neutralIsoPtSumWeight, reco::LeafCandidate::p4(), tauProducer_cfi::photonPtSumOutsideSignalCone, EnergyCorrector::pt, pat::Tau::ptLeadChargedCand(), tauProducer_cfi::puCorrPtSum, metsig::tau, TauIdMVAAuxiliaries::tau_Eratio(), TauIdMVAAuxiliaries::tau_n_photons_total(), TauIdMVAAuxiliaries::tau_pt_weighted_deta_strip(), TauIdMVAAuxiliaries::tau_pt_weighted_dphi_strip(), TauIdMVAAuxiliaries::tau_pt_weighted_dr_iso(), TauIdMVAAuxiliaries::tau_pt_weighted_dr_signal(), and pat::Tau::tauID().

1375  {
1376  static constexpr bool check_all_set = false;
1377  static constexpr float default_value_for_set_check = -42;
1379 
1380  tensorflow::Tensor inputs(tensorflow::DT_FLOAT, { 1, dnn_inputs_2017v1::NumberOfInputs});
1381  const auto& get = [&](int var_index) -> float& { return inputs.matrix<float>()(0, var_index); };
1382  auto leadChargedHadrCand = dynamic_cast<const pat::PackedCandidate*>(tau.leadChargedHadrCand().get());
1383 
1384  if(check_all_set) {
1385  for(int var_index = 0; var_index < dnn::NumberOfInputs; ++var_index) {
1386  get(var_index) = default_value_for_set_check;
1387  }
1388  }
1389 
1390  get(dnn::pt) = tau.p4().pt();
1391  get(dnn::eta) = tau.p4().eta();
1392  get(dnn::mass) = tau.p4().mass();
1393  get(dnn::decayMode) = tau.decayMode();
1394  get(dnn::chargedIsoPtSum) = tau.tauID("chargedIsoPtSum");
1395  get(dnn::neutralIsoPtSum) = tau.tauID("neutralIsoPtSum");
1396  get(dnn::neutralIsoPtSumWeight) = tau.tauID("neutralIsoPtSumWeight");
1397  get(dnn::photonPtSumOutsideSignalCone) = tau.tauID("photonPtSumOutsideSignalCone");
1398  get(dnn::puCorrPtSum) = tau.tauID("puCorrPtSum");
1399  get(dnn::dxy) = tau.dxy();
1400  get(dnn::dxy_sig) = tau.dxy_Sig();
1401  get(dnn::dz) = leadChargedHadrCand ? leadChargedHadrCand->dz() : default_value;
1402  get(dnn::ip3d) = tau.ip3d();
1403  get(dnn::ip3d_sig) = tau.ip3d_Sig();
1404  get(dnn::hasSecondaryVertex) = tau.hasSecondaryVertex();
1405  get(dnn::flightLength_r) = tau.flightLength().R();
1406  get(dnn::flightLength_dEta) = dEta(tau.flightLength(), tau.p4());
1407  get(dnn::flightLength_dPhi) = dPhi(tau.flightLength(), tau.p4());
1408  get(dnn::flightLength_sig) = tau.flightLengthSig();
1409  get(dnn::leadChargedHadrCand_pt) = leadChargedHadrCand ? leadChargedHadrCand->p4().Pt() : default_value;
1410  get(dnn::leadChargedHadrCand_dEta) = leadChargedHadrCand
1411  ? dEta(leadChargedHadrCand->p4(), tau.p4()) : default_value;
1412  get(dnn::leadChargedHadrCand_dPhi) = leadChargedHadrCand
1413  ? dPhi(leadChargedHadrCand->p4(), tau.p4()) : default_value;
1414  get(dnn::leadChargedHadrCand_mass) = leadChargedHadrCand
1415  ? leadChargedHadrCand->p4().mass() : default_value;
1416  get(dnn::pt_weighted_deta_strip) = clusterVariables.tau_pt_weighted_deta_strip(tau, tau.decayMode());
1417  get(dnn::pt_weighted_dphi_strip) = clusterVariables.tau_pt_weighted_dphi_strip(tau, tau.decayMode());
1418  get(dnn::pt_weighted_dr_signal) = clusterVariables.tau_pt_weighted_dr_signal(tau, tau.decayMode());
1419  get(dnn::pt_weighted_dr_iso) = clusterVariables.tau_pt_weighted_dr_iso(tau, tau.decayMode());
1420  get(dnn::leadingTrackNormChi2) = tau.leadingTrackNormChi2();
1421  get(dnn::e_ratio) = clusterVariables.tau_Eratio(tau);
1422  get(dnn::gj_angle_diff) = calculateGottfriedJacksonAngleDifference(tau);
1423  get(dnn::n_photons) = clusterVariables.tau_n_photons_total(tau);
1424  get(dnn::emFraction) = tau.emFraction_MVA();
1425  get(dnn::has_gsf_track) = leadChargedHadrCand && std::abs(leadChargedHadrCand->pdgId()) == 11;
1426  get(dnn::inside_ecal_crack) = isInEcalCrack(tau.p4().Eta());
1427  auto gsf_ele = findMatchedElectron(tau, electrons, 0.3);
1428  get(dnn::gsf_ele_matched) = gsf_ele != nullptr;
1429  get(dnn::gsf_ele_pt) = gsf_ele != nullptr ? gsf_ele->p4().Pt() : default_value;
1430  get(dnn::gsf_ele_dEta) = gsf_ele != nullptr ? dEta(gsf_ele->p4(), tau.p4()) : default_value;
1431  get(dnn::gsf_ele_dPhi) = gsf_ele != nullptr ? dPhi(gsf_ele->p4(), tau.p4()) : default_value;
1432  get(dnn::gsf_ele_mass) = gsf_ele != nullptr ? gsf_ele->p4().mass() : default_value;
1433  calculateElectronClusterVars(gsf_ele, get(dnn::gsf_ele_Ee), get(dnn::gsf_ele_Egamma));
1434  get(dnn::gsf_ele_Pin) = gsf_ele != nullptr ? gsf_ele->trackMomentumAtVtx().R() : default_value;
1435  get(dnn::gsf_ele_Pout) = gsf_ele != nullptr ? gsf_ele->trackMomentumOut().R() : default_value;
1436  get(dnn::gsf_ele_EtotOverPin) = get(dnn::gsf_ele_Pin) > 0
1437  ? (get(dnn::gsf_ele_Ee) + get(dnn::gsf_ele_Egamma)) / get(dnn::gsf_ele_Pin)
1438  : default_value;
1439  get(dnn::gsf_ele_Eecal) = gsf_ele != nullptr ? gsf_ele->ecalEnergy() : default_value;
1440  get(dnn::gsf_ele_dEta_SeedClusterTrackAtCalo) = gsf_ele != nullptr
1441  ? gsf_ele->deltaEtaSeedClusterTrackAtCalo() : default_value;
1442  get(dnn::gsf_ele_dPhi_SeedClusterTrackAtCalo) = gsf_ele != nullptr
1443  ? gsf_ele->deltaPhiSeedClusterTrackAtCalo() : default_value;
1444  get(dnn::gsf_ele_mvaIn_sigmaEtaEta) = gsf_ele != nullptr
1445  ? gsf_ele->mvaInput().sigmaEtaEta : default_value;
1446  get(dnn::gsf_ele_mvaIn_hadEnergy) = gsf_ele != nullptr ? gsf_ele->mvaInput().hadEnergy : default_value;
1447  get(dnn::gsf_ele_mvaIn_deltaEta) = gsf_ele != nullptr ? gsf_ele->mvaInput().deltaEta : default_value;
1448 
1449  get(dnn::gsf_ele_Chi2NormGSF) = default_value;
1450  get(dnn::gsf_ele_GSFNumHits) = default_value;
1451  get(dnn::gsf_ele_GSFTrackResol) = default_value;
1452  get(dnn::gsf_ele_GSFTracklnPt) = default_value;
1453  if(gsf_ele != nullptr && gsf_ele->gsfTrack().isNonnull()) {
1454  get(dnn::gsf_ele_Chi2NormGSF) = gsf_ele->gsfTrack()->normalizedChi2();
1455  get(dnn::gsf_ele_GSFNumHits) = gsf_ele->gsfTrack()->numberOfValidHits();
1456  if(gsf_ele->gsfTrack()->pt() > 0) {
1457  get(dnn::gsf_ele_GSFTrackResol) = gsf_ele->gsfTrack()->ptError() / gsf_ele->gsfTrack()->pt();
1458  get(dnn::gsf_ele_GSFTracklnPt) = std::log10(gsf_ele->gsfTrack()->pt());
1459  }
1460  }
1461 
1462  get(dnn::gsf_ele_Chi2NormKF) = default_value;
1463  get(dnn::gsf_ele_KFNumHits) = default_value;
1464  if(gsf_ele != nullptr && gsf_ele->closestCtfTrackRef().isNonnull()) {
1465  get(dnn::gsf_ele_Chi2NormKF) = gsf_ele->closestCtfTrackRef()->normalizedChi2();
1466  get(dnn::gsf_ele_KFNumHits) = gsf_ele->closestCtfTrackRef()->numberOfValidHits();
1467  }
1468  get(dnn::leadChargedCand_etaAtEcalEntrance) = tau.etaAtEcalEntranceLeadChargedCand();
1469  get(dnn::leadChargedCand_pt) = tau.ptLeadChargedCand();
1470 
1471  get(dnn::leadChargedHadrCand_HoP) = default_value;
1472  get(dnn::leadChargedHadrCand_EoP) = default_value;
1473  if(tau.leadChargedHadrCand()->pt() > 0) {
1474  get(dnn::leadChargedHadrCand_HoP) = tau.hcalEnergyLeadChargedHadrCand()
1475  / tau.leadChargedHadrCand()->pt();
1476  get(dnn::leadChargedHadrCand_EoP) = tau.ecalEnergyLeadChargedHadrCand()
1477  / tau.leadChargedHadrCand()->pt();
1478  }
1479 
1480  MuonHitMatchV1 muon_hit_match;
1481  if(tau.leadPFChargedHadrCand().isNonnull() && tau.leadPFChargedHadrCand()->muonRef().isNonnull())
1482  muon_hit_match.addMatchedMuon(*tau.leadPFChargedHadrCand()->muonRef(), tau);
1483 
1484  auto matched_muons = muon_hit_match.findMatchedMuons(tau, muons, 0.3, 5);
1485  for(auto muon : matched_muons)
1486  muon_hit_match.addMatchedMuon(*muon, tau);
1487  muon_hit_match.fillTensor<dnn>(get, tau, default_value);
1488 
1489  LorentzVectorXYZ signalChargedHadrCands_sumIn, signalChargedHadrCands_sumOut;
1490  processSignalPFComponents(tau, tau.signalChargedHadrCands(),
1491  signalChargedHadrCands_sumIn, signalChargedHadrCands_sumOut,
1492  get(dnn::signalChargedHadrCands_sum_innerSigCone_pt),
1493  get(dnn::signalChargedHadrCands_sum_innerSigCone_dEta),
1494  get(dnn::signalChargedHadrCands_sum_innerSigCone_dPhi),
1495  get(dnn::signalChargedHadrCands_sum_innerSigCone_mass),
1496  get(dnn::signalChargedHadrCands_sum_outerSigCone_pt),
1497  get(dnn::signalChargedHadrCands_sum_outerSigCone_dEta),
1498  get(dnn::signalChargedHadrCands_sum_outerSigCone_dPhi),
1499  get(dnn::signalChargedHadrCands_sum_outerSigCone_mass),
1500  get(dnn::signalChargedHadrCands_nTotal_innerSigCone),
1501  get(dnn::signalChargedHadrCands_nTotal_outerSigCone));
1502 
1503  LorentzVectorXYZ signalNeutrHadrCands_sumIn, signalNeutrHadrCands_sumOut;
1504  processSignalPFComponents(tau, tau.signalNeutrHadrCands(),
1505  signalNeutrHadrCands_sumIn, signalNeutrHadrCands_sumOut,
1506  get(dnn::signalNeutrHadrCands_sum_innerSigCone_pt),
1507  get(dnn::signalNeutrHadrCands_sum_innerSigCone_dEta),
1508  get(dnn::signalNeutrHadrCands_sum_innerSigCone_dPhi),
1509  get(dnn::signalNeutrHadrCands_sum_innerSigCone_mass),
1510  get(dnn::signalNeutrHadrCands_sum_outerSigCone_pt),
1511  get(dnn::signalNeutrHadrCands_sum_outerSigCone_dEta),
1512  get(dnn::signalNeutrHadrCands_sum_outerSigCone_dPhi),
1513  get(dnn::signalNeutrHadrCands_sum_outerSigCone_mass),
1514  get(dnn::signalNeutrHadrCands_nTotal_innerSigCone),
1515  get(dnn::signalNeutrHadrCands_nTotal_outerSigCone));
1516 
1517 
1518  LorentzVectorXYZ signalGammaCands_sumIn, signalGammaCands_sumOut;
1519  processSignalPFComponents(tau, tau.signalGammaCands(),
1520  signalGammaCands_sumIn, signalGammaCands_sumOut,
1521  get(dnn::signalGammaCands_sum_innerSigCone_pt),
1522  get(dnn::signalGammaCands_sum_innerSigCone_dEta),
1523  get(dnn::signalGammaCands_sum_innerSigCone_dPhi),
1524  get(dnn::signalGammaCands_sum_innerSigCone_mass),
1525  get(dnn::signalGammaCands_sum_outerSigCone_pt),
1526  get(dnn::signalGammaCands_sum_outerSigCone_dEta),
1527  get(dnn::signalGammaCands_sum_outerSigCone_dPhi),
1528  get(dnn::signalGammaCands_sum_outerSigCone_mass),
1529  get(dnn::signalGammaCands_nTotal_innerSigCone),
1530  get(dnn::signalGammaCands_nTotal_outerSigCone));
1531 
1532  LorentzVectorXYZ isolationChargedHadrCands_sum;
1533  processIsolationPFComponents(tau, tau.isolationChargedHadrCands(), isolationChargedHadrCands_sum,
1534  get(dnn::isolationChargedHadrCands_sum_pt),
1535  get(dnn::isolationChargedHadrCands_sum_dEta),
1536  get(dnn::isolationChargedHadrCands_sum_dPhi),
1537  get(dnn::isolationChargedHadrCands_sum_mass),
1538  get(dnn::isolationChargedHadrCands_nTotal));
1539 
1540  LorentzVectorXYZ isolationNeutrHadrCands_sum;
1541  processIsolationPFComponents(tau, tau.isolationNeutrHadrCands(), isolationNeutrHadrCands_sum,
1542  get(dnn::isolationNeutrHadrCands_sum_pt),
1543  get(dnn::isolationNeutrHadrCands_sum_dEta),
1544  get(dnn::isolationNeutrHadrCands_sum_dPhi),
1545  get(dnn::isolationNeutrHadrCands_sum_mass),
1546  get(dnn::isolationNeutrHadrCands_nTotal));
1547 
1548  LorentzVectorXYZ isolationGammaCands_sum;
1549  processIsolationPFComponents(tau, tau.isolationGammaCands(), isolationGammaCands_sum,
1550  get(dnn::isolationGammaCands_sum_pt),
1551  get(dnn::isolationGammaCands_sum_dEta),
1552  get(dnn::isolationGammaCands_sum_dPhi),
1553  get(dnn::isolationGammaCands_sum_mass),
1554  get(dnn::isolationGammaCands_nTotal));
1555 
1556  get(dnn::tau_visMass_innerSigCone) = (signalGammaCands_sumIn + signalChargedHadrCands_sumIn).mass();
1557 
1558  if(check_all_set) {
1559  for(int var_index = 0; var_index < dnn::NumberOfInputs; ++var_index) {
1560  if(get(var_index) == default_value_for_set_check)
1561  throw cms::Exception("DeepTauId: variable with index = ") << var_index << " is not set.";
1562  }
1563  }
1564 
1565  return inputs;
1566  }
float tau_Eratio(const reco::PFTau &tau) const
return ratio of energy in ECAL over sum of energy in ECAL and HCAL
static bool isInEcalCrack(double eta)
Definition: DeepTauId.cc:1676
static void processIsolationPFComponents(const pat::Tau &tau, const CandidateCollection &candidates, LorentzVectorXYZ &p4, float &pt, float &d_eta, float &d_phi, float &m, float &n)
Definition: DeepTauId.cc:1623
#define constexpr
TauIdMVAAuxiliaries clusterVariables
Definition: DeepTauId.cc:1706
float tau_pt_weighted_dphi_strip(const reco::PFTau &tau, int dm) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
float tau_pt_weighted_dr_signal(const reco::PFTau &tau, int dm) const
float tau_pt_weighted_dr_iso(const reco::PFTau &tau, int dm) const
float tau_pt_weighted_deta_strip(const reco::PFTau &tau, int dm) const
static void processSignalPFComponents(const pat::Tau &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)
Definition: DeepTauId.cc:1587
static bool calculateGottfriedJacksonAngleDifference(const pat::Tau &tau, double &gj_diff)
Definition: DeepTauId.cc:1649
static const pat::Electron * findMatchedElectron(const pat::Tau &tau, const pat::ElectronCollection &electrons, double deltaR)
Definition: DeepTauId.cc:1682
static float default_value
Definition: DeepTauId.cc:554
static void calculateElectronClusterVars(const pat::Electron *ele, float &elecEe, float &elecEgamma)
Definition: DeepTauId.cc:1568
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double >> LorentzVectorXYZ
Definition: DeepTauBase.h:67
unsigned int tau_n_photons_total(const reco::PFTau &tau) const
return total number of pf photon candidates with pT>500 MeV, which are associated to signal ...
void DeepTauId::createMuonBlockInputs ( const TauType tau,
const reco::Vertex pv,
double  rho,
const pat::MuonCollection muons,
const pat::PackedCandidateCollection pfCands,
const Cell &  cell_map,
bool  is_inner 
)
inlineprivate

Definition at line 1156 of file DeepTauId.cc.

References funct::abs(), MuonSubdetId::CSC, particleFlow_cfi::dPhi, MuonSubdetId::DT, f, pat::Tau::flightLength(), objects.autophobj::float, reco::JetExtendedAssociation::getValue(), PatBasicFWLiteJetAnalyzer_Selector_cfg::inputs, nanoDQM_cfi::Muon, reco::LeafCandidate::polarP4(), reco::Vertex::position(), pat::Muon::PV2D, MuonSubdetId::RPC, relativeConstraints::station, runTauDisplay::tau_eta, and runTauDisplay::tau_pt.

1160  {
1161  namespace dnn = dnn_inputs_2017_v2::MuonBlockInputs;
1162 
1163  tensorflow::Tensor& inputs = *muonTensor_.at(is_inner);
1164  inputs.flat<float>().setZero();
1165 
1166  const auto& get = [&](int var_index) -> float& {
1167  return inputs.tensor<float,4>()(0, 0, 0, var_index);
1168  };
1169 
1170  const bool valid_index_pf_muon = cell_map.count(CellObjectType::PfCand_muon);
1171  const bool valid_index_muon = cell_map.count(CellObjectType::Muon);
1172 
1173  if(!cell_map.empty()){
1174  get(dnn::rho) = getValueNorm(rho, 21.49f, 9.713f);
1175  get(dnn::tau_pt) = getValueLinear(tau.polarP4().pt(), 20.f, 1000.f, true);
1176  get(dnn::tau_eta) = getValueLinear(tau.polarP4().eta(), -2.3f, 2.3f, false);
1177  get(dnn::tau_inside_ecal_crack) = getValue(isInEcalCrack(tau.polarP4().eta()));
1178  }
1179  if(valid_index_pf_muon){
1180  size_t index_pf_muon = cell_map.at(CellObjectType::PfCand_muon);
1181 
1182  get(dnn::pfCand_muon_valid) = valid_index_pf_muon;
1183  get(dnn::pfCand_muon_rel_pt) = getValueNorm(pfCands.at(index_pf_muon).polarP4().pt() / tau.polarP4().pt(),
1184  is_inner ? 0.9509f : 0.0861f, is_inner ? 0.4294f : 0.4065f);
1185  get(dnn::pfCand_muon_deta) = getValueLinear(pfCands.at(index_pf_muon).polarP4().eta() - tau.polarP4().eta(),
1186  is_inner ? -0.1f : -0.5f, is_inner ? 0.1f : 0.5f, false);
1187  get(dnn::pfCand_muon_dphi) = getValueLinear(dPhi(tau.polarP4(), pfCands.at(index_pf_muon).polarP4()),
1188  is_inner ? -0.1f : -0.5f, is_inner ? 0.1f : 0.5f, false);
1189  get(dnn::pfCand_muon_pvAssociationQuality) = getValueLinear<int>(pfCands.at(index_pf_muon).pvAssociationQuality(), 0, 7, true);
1190  get(dnn::pfCand_muon_fromPV) = getValueLinear<int>(pfCands.at(index_pf_muon).fromPV(), 0, 3, true);
1191  get(dnn::pfCand_muon_puppiWeight) = getValue(pfCands.at(index_pf_muon).puppiWeight());
1192  get(dnn::pfCand_muon_charge) = getValue(pfCands.at(index_pf_muon).charge());
1193  get(dnn::pfCand_muon_lostInnerHits) = getValue<int>(pfCands.at(index_pf_muon).lostInnerHits());
1194  get(dnn::pfCand_muon_numberOfPixelHits) = getValueLinear(pfCands.at(index_pf_muon).numberOfPixelHits(), 0, 11, true);
1195  get(dnn::pfCand_muon_vertex_dx) = getValueNorm(pfCands.at(index_pf_muon).vertex().x() - pv.position().x(), -0.0007f, 0.6869f);
1196  get(dnn::pfCand_muon_vertex_dy) = getValueNorm(pfCands.at(index_pf_muon).vertex().y() - pv.position().y(), 0.0001f, 0.6784f);
1197  get(dnn::pfCand_muon_vertex_dz) = getValueNorm(pfCands.at(index_pf_muon).vertex().z() - pv.position().z(), -0.0117f, 4.097f);
1198  get(dnn::pfCand_muon_vertex_dx_tauFL) = getValueNorm(pfCands.at(index_pf_muon).vertex().x() -
1199  pv.position().x() - tau.flightLength().x(), -0.0001f, 0.8642f);
1200  get(dnn::pfCand_muon_vertex_dy_tauFL) = getValueNorm(pfCands.at(index_pf_muon).vertex().y() -
1201  pv.position().y() - tau.flightLength().y(), 0.0004f, 0.8561f);
1202  get(dnn::pfCand_muon_vertex_dz_tauFL) = getValueNorm(pfCands.at(index_pf_muon).vertex().z() -
1203  pv.position().z() - tau.flightLength().z(), -0.0118f, 4.405f);
1204 
1205  const bool hasTrackDetails = pfCands.at(index_pf_muon).hasTrackDetails();
1206  if(hasTrackDetails){
1207  get(dnn::pfCand_muon_hasTrackDetails) = hasTrackDetails;
1208  get(dnn::pfCand_muon_dxy) = getValueNorm(pfCands.at(index_pf_muon).dxy(), -0.0045f, 0.9655f);
1209  get(dnn::pfCand_muon_dxy_sig) = getValueNorm(std::abs(pfCands.at(index_pf_muon).dxy()) /
1210  pfCands.at(index_pf_muon).dxyError(), 4.575f, 42.36f);
1211  get(dnn::pfCand_muon_dz) = getValueNorm(pfCands.at(index_pf_muon).dz(), -0.0117f, 4.097f);
1212  get(dnn::pfCand_muon_dz_sig) = getValueNorm(std::abs(pfCands.at(index_pf_muon).dz()) /
1213  pfCands.at(index_pf_muon).dzError(), 80.37f, 343.3f);
1214  get(dnn::pfCand_muon_track_chi2_ndof) = getValueNorm(pfCands.at(index_pf_muon).pseudoTrack().chi2() /
1215  pfCands.at(index_pf_muon).pseudoTrack().ndof(), 0.69f, 1.711f);
1216  get(dnn::pfCand_muon_track_ndof) = getValueNorm(pfCands.at(index_pf_muon).pseudoTrack().ndof(), 17.5f, 5.11f);
1217  }
1218  }
1219  if(valid_index_muon){
1220  size_t index_muon = cell_map.at(CellObjectType::Muon);
1221 
1222  get(dnn::muon_valid) = valid_index_muon;
1223  get(dnn::muon_rel_pt) = getValueNorm(muons.at(index_muon).polarP4().pt() / tau.polarP4().pt(),
1224  is_inner ? 0.7966f : 0.2678f, is_inner ? 3.402f : 3.592f);
1225  get(dnn::muon_deta) = getValueLinear(muons.at(index_muon).polarP4().eta() - tau.polarP4().eta(),
1226  is_inner ? -0.1f : -0.5f, is_inner ? 0.1f : 0.5f, false);
1227  get(dnn::muon_dphi) = getValueLinear(dPhi(tau.polarP4(), muons.at(index_muon).polarP4()),
1228  is_inner ? -0.1f : -0.5f, is_inner ? 0.1f : 0.5f, false);
1229  get(dnn::muon_dxy) = getValueNorm(muons.at(index_muon).dB(pat::Muon::PV2D), 0.0019f, 1.039f);
1230  get(dnn::muon_dxy_sig) = getValueNorm(std::abs(muons.at(index_muon).dB(pat::Muon::PV2D)) /
1231  muons.at(index_muon).edB(pat::Muon::PV2D), 8.98f, 71.17f);
1232 
1233  const bool normalizedChi2_valid = muons.at(index_muon).globalTrack().isNonnull() && muons.at(index_muon).normChi2() >= 0;
1234  if(normalizedChi2_valid){
1235  get(dnn::muon_normalizedChi2_valid) = normalizedChi2_valid;
1236  get(dnn::muon_normalizedChi2) = getValueNorm(muons.at(index_muon).normChi2(), 21.52f, 265.8f);
1237  if(muons.at(index_muon).innerTrack().isNonnull())
1238  get(dnn::muon_numberOfValidHits) = getValueNorm(muons.at(index_muon).numberOfValidHits(), 21.84f, 10.59f);
1239  }
1240  get(dnn::muon_segmentCompatibility) = getValue(muons.at(index_muon).segmentCompatibility());
1241  get(dnn::muon_caloCompatibility) = getValue(muons.at(index_muon).caloCompatibility());
1242 
1243  const bool pfEcalEnergy_valid = muons.at(index_muon).pfEcalEnergy() >= 0;
1244  if(pfEcalEnergy_valid){
1245  get(dnn::muon_pfEcalEnergy_valid) = pfEcalEnergy_valid;
1246  get(dnn::muon_rel_pfEcalEnergy) = getValueNorm(muons.at(index_muon).pfEcalEnergy() /
1247  muons.at(index_muon).polarP4().pt(), 0.2273f, 0.4865f);
1248  }
1249 
1250  MuonHitMatchV2 hit_match(muons.at(index_muon));
1251  static const std::map<int, std::pair<int, int>> muonMatchHitVars = {
1252  { MuonSubdetId::DT, { dnn::muon_n_matches_DT_1, dnn::muon_n_hits_DT_1 } },
1253  { MuonSubdetId::CSC, { dnn::muon_n_matches_CSC_1, dnn::muon_n_hits_CSC_1 } },
1254  { MuonSubdetId::RPC, { dnn::muon_n_matches_RPC_1, dnn::muon_n_hits_RPC_1 } }
1255  };
1256 
1257  static const std::map<int, std::vector<float>> muonMatchVarLimits = {
1258  { MuonSubdetId::DT, { 2, 2, 2, 2 } },
1259  { MuonSubdetId::CSC, { 6, 2, 2, 2 } },
1260  { MuonSubdetId::RPC, { 7, 6, 4, 4 } }
1261  };
1262 
1263  static const std::map<int, std::vector<float>> muonHitVarLimits = {
1264  { MuonSubdetId::DT, { 12, 12, 12, 8 } },
1265  { MuonSubdetId::CSC, { 24, 12, 12, 12 } },
1266  { MuonSubdetId::RPC, { 4, 4, 2, 2 } }
1267  };
1268 
1269  for(int subdet : hit_match.MuonHitMatchV2::consideredSubdets()) {
1270  const auto& matchHitVar = muonMatchHitVars.at(subdet);
1271  const auto& matchLimits = muonMatchVarLimits.at(subdet);
1272  const auto& hitLimits = muonHitVarLimits.at(subdet);
1273  for(int station = MuonHitMatchV2::first_station_id; station <= MuonHitMatchV2::last_station_id; ++station) {
1274  const unsigned n_matches = hit_match.nMatches(subdet, station);
1275  const unsigned n_hits = hit_match.nHits(subdet, station);
1276  get(matchHitVar.first + station - 1) = getValueLinear(n_matches, 0, matchLimits.at(station - 1), true);
1277  get(matchHitVar.second + station - 1) = getValueLinear(n_hits, 0, hitLimits.at(station - 1), true);
1278  }
1279  }
1280  }
1281  checkInputs(inputs, is_inner ? "muon_inner_block" : "muon_outer_block", dnn::NumberOfInputs);
1282  }
static float getValueLinear(T value, float min_value, float max_value, bool positive)
Definition: DeepTauId.cc:664
static bool isInEcalCrack(double eta)
Definition: DeepTauId.cc:1676
const Point & position() const
position
Definition: Vertex.h:109
std::array< std::shared_ptr< tensorflow::Tensor >, 2 > muonTensor_
Definition: DeepTauId.cc:1704
static float getValue(T value)
Definition: DeepTauId.cc:658
static float getValueNorm(T value, float mean, float sigma, float n_sigmas_max=5)
Definition: DeepTauId.cc:675
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
static constexpr int RPC
Definition: MuonSubdetId.h:14
void checkInputs(const tensorflow::Tensor &inputs, const char *block_name, int n_inputs, int n_eta=1, int n_phi=1) const
Definition: DeepTauId.cc:704
static constexpr int DT
Definition: MuonSubdetId.h:12
static constexpr int CSC
Definition: MuonSubdetId.h:13
void DeepTauId::createTauBlockInputs ( const TauType tau,
const reco::Vertex pv,
double  rho 
)
inlineprivate

Definition at line 881 of file DeepTauId.cc.

References funct::abs(), reco::LeafCandidate::charge(), tauProducer_cfi::chargedIsoPtSum, pat::Tau::decayMode(), pat::Tau::dxy(), pat::Tau::dxy_error(), pat::Tau::dxy_PCA(), pat::Tau::emFraction_MVA(), pat::Tau::etaAtEcalEntranceLeadChargedCand(), f, pat::Tau::flightLength(), tauProducer_cfi::footprintCorrection, edm::Ptr< T >::get(), reco::JetExtendedAssociation::getValue(), PatBasicFWLiteJetAnalyzer_Selector_cfg::inputs, pat::Tau::ip3d(), pat::Tau::ip3d_error(), pat::Tau::leadChargedHadrCand(), pat::Tau::leadingTrackNormChi2(), tauProducer_cfi::neutralIsoPtSum, reco::LeafCandidate::p4(), tauProducer_cfi::photonPtSumOutsideSignalCone, pi, reco::LeafCandidate::polarP4(), tauProducer_cfi::puCorrPtSum, runTauDisplay::tau_eta, runTauDisplay::tau_mass, runTauDisplay::tau_phi, runTauDisplay::tau_pt, and pat::Tau::tauID().

882  {
883  namespace dnn = dnn_inputs_2017_v2::TauBlockInputs;
884 
885  tensorflow::Tensor& inputs = *tauBlockTensor_;
886  inputs.flat<float>().setZero();
887 
888  const auto& get = [&](int var_index) -> float& { return inputs.matrix<float>()(0, var_index); };
889 
890  auto leadChargedHadrCand = dynamic_cast<const pat::PackedCandidate*>(tau.leadChargedHadrCand().get());
891 
892  get(dnn::rho) = getValueNorm(rho, 21.49f, 9.713f);
893  get(dnn::tau_pt) = getValueLinear(tau.polarP4().pt(), 20.f, 1000.f, true);
894  get(dnn::tau_eta) = getValueLinear(tau.polarP4().eta(), -2.3f, 2.3f, false);
895  get(dnn::tau_phi) = getValueLinear(tau.polarP4().phi(), -pi, pi, false);
896  get(dnn::tau_mass) = getValueNorm(tau.polarP4().mass(), 0.6669f, 0.6553f);
897  get(dnn::tau_E_over_pt) = getValueLinear(tau.p4().energy() / tau.p4().pt(), 1.f, 5.2f, true);
898  get(dnn::tau_charge) = getValue(tau.charge());
899  get(dnn::tau_n_charged_prongs) = getValueLinear(tau.decayMode() / 5 + 1, 1, 3, true);
900  get(dnn::tau_n_neutral_prongs) = getValueLinear(tau.decayMode() % 5, 0, 2, true);
901  get(dnn::chargedIsoPtSum) = getValueNorm(tau.tauID("chargedIsoPtSum"), 47.78f, 123.5f);
902  get(dnn::chargedIsoPtSumdR03_over_dR05) = getValue(tau.tauID("chargedIsoPtSumdR03") / tau.tauID("chargedIsoPtSum"));
903  get(dnn::footprintCorrection) = getValueNorm(tau.tauID("footprintCorrectiondR03"), 9.029f, 26.42f);
904  get(dnn::neutralIsoPtSum) = getValueNorm(tau.tauID("neutralIsoPtSum"), 57.59f, 155.3f);
905  get(dnn::neutralIsoPtSumWeight_over_neutralIsoPtSum) =
906  getValue(tau.tauID("neutralIsoPtSumWeight") / tau.tauID("neutralIsoPtSum"));
907  get(dnn::neutralIsoPtSumWeightdR03_over_neutralIsoPtSum) =
908  getValue(tau.tauID("neutralIsoPtSumWeightdR03") / tau.tauID("neutralIsoPtSum"));
909  get(dnn::neutralIsoPtSumdR03_over_dR05) = getValue(tau.tauID("neutralIsoPtSumdR03") / tau.tauID("neutralIsoPtSum"));
910  get(dnn::photonPtSumOutsideSignalCone) = getValueNorm(tau.tauID("photonPtSumOutsideSignalConedR03"), 1.731f, 6.846f);
911  get(dnn::puCorrPtSum) = getValueNorm(tau.tauID("puCorrPtSum"), 22.38f, 16.34f);
912  // The global PCA coordinates were used as inputs during the NN training, but it was decided to disable
913  // them for the inference, because modeling of dxy_PCA in MC poorly describes the data, and x and y coordinates
914  // in data results outside of the expected 5 std. dev. input validity range. On the other hand,
915  // these coordinates are strongly era-dependent. Kept as comment to document what NN expects.
916  if (!disable_dxy_pca_) {
917  get(dnn::tau_dxy_pca_x) = getValueNorm(tau.dxy_PCA().x(), -0.0241f, 0.0074f);
918  get(dnn::tau_dxy_pca_y) = getValueNorm(tau.dxy_PCA().y(),0.0675f, 0.0128f);
919  get(dnn::tau_dxy_pca_z) = getValueNorm(tau.dxy_PCA().z(), 0.7973f, 3.456f);
920  } else {
921  get(dnn::tau_dxy_pca_x) = 0;
922  get(dnn::tau_dxy_pca_y) = 0;
923  get(dnn::tau_dxy_pca_z) = 0;
924  }
925 
926  const bool tau_dxy_valid = std::isnormal(tau.dxy()) && tau.dxy() > - 10 && std::isnormal(tau.dxy_error())
927  && tau.dxy_error() > 0;
928  if(tau_dxy_valid){
929  get(dnn::tau_dxy_valid) = tau_dxy_valid;
930  get(dnn::tau_dxy) = getValueNorm(tau.dxy(), 0.0018f, 0.0085f);
931  get(dnn::tau_dxy_sig) = getValueNorm(std::abs(tau.dxy())/tau.dxy_error(), 2.26f, 4.191f);
932  }
933  const bool tau_ip3d_valid = std::isnormal(tau.ip3d()) && tau.ip3d() > - 10 && std::isnormal(tau.ip3d_error())
934  && tau.ip3d_error() > 0;
935  if(tau_ip3d_valid){
936  get(dnn::tau_ip3d_valid) = tau_ip3d_valid;
937  get(dnn::tau_ip3d) = getValueNorm(tau.ip3d(), 0.0026f, 0.0114f);
938  get(dnn::tau_ip3d_sig) = getValueNorm(std::abs(tau.ip3d()) / tau.ip3d_error(), 2.928f, 4.466f);
939  }
940  if(leadChargedHadrCand){
941  get(dnn::tau_dz) = getValueNorm(leadChargedHadrCand->dz(), 0.f, 0.0190f);
942  const bool tau_dz_sig_valid = leadChargedHadrCand->hasTrackDetails() && std::isnormal(leadChargedHadrCand->dz())
943  && std::isnormal(leadChargedHadrCand->dzError()) && leadChargedHadrCand->dzError() > 0;
944  get(dnn::tau_dz_sig_valid) = tau_dz_sig_valid;
945  const double dzError = leadChargedHadrCand->hasTrackDetails() ? leadChargedHadrCand->dzError() : default_value;
946  get(dnn::tau_dz_sig) = getValueNorm(std::abs(leadChargedHadrCand->dz()) / dzError, 4.717f, 11.78f);
947  }
948  get(dnn::tau_flightLength_x) = getValueNorm(tau.flightLength().x(), -0.0003f, 0.7362f);
949  get(dnn::tau_flightLength_y) = getValueNorm(tau.flightLength().y(), -0.0009f, 0.7354f);
950  get(dnn::tau_flightLength_z) = getValueNorm(tau.flightLength().z(), -0.0022f, 1.993f);
951  // get(dnn::tau_flightLength_sig) = getValueNorm(tau.flightLengthSig(), -4.78f, 9.573f);
952  get(dnn::tau_flightLength_sig) = 0.55756444; //This value is set due to a bug in the training
953  get(dnn::tau_pt_weighted_deta_strip) = getValueLinear(clusterVariables.tau_pt_weighted_deta_strip(tau, tau.decayMode()), 0, 1, true);
954 
955  get(dnn::tau_pt_weighted_dphi_strip) = getValueLinear(clusterVariables.tau_pt_weighted_dphi_strip(tau, tau.decayMode()), 0, 1, true);
956  get(dnn::tau_pt_weighted_dr_signal) = getValueNorm(clusterVariables.tau_pt_weighted_dr_signal(tau, tau.decayMode()), 0.0052f, 0.01433f);
957  get(dnn::tau_pt_weighted_dr_iso) = getValueLinear(clusterVariables.tau_pt_weighted_dr_iso(tau,tau.decayMode()), 0, 1, true);
958  get(dnn::tau_leadingTrackNormChi2) = getValueNorm(tau.leadingTrackNormChi2(), 1.538f, 4.401f);
959  const auto eratio = clusterVariables.tau_Eratio(tau);
960  const bool tau_e_ratio_valid = std::isnormal(eratio) && eratio > 0.f;
961  get(dnn::tau_e_ratio_valid) = tau_e_ratio_valid;
962  get(dnn::tau_e_ratio) = tau_e_ratio_valid ? getValueLinear(eratio, 0, 1, true) : 0.f;
963  const double gj_angle_diff = calculateGottfriedJacksonAngleDifference(tau);
964  const bool tau_gj_angle_diff_valid = (std::isnormal(gj_angle_diff) || gj_angle_diff == 0) && gj_angle_diff >= 0;
965  get(dnn::tau_gj_angle_diff_valid) = tau_gj_angle_diff_valid;
966  get(dnn::tau_gj_angle_diff) = tau_gj_angle_diff_valid ? getValueLinear(gj_angle_diff, 0, pi, true) : 0;
967  get(dnn::tau_n_photons) = getValueNorm(clusterVariables.tau_n_photons_total(tau), 2.95f, 3.927f);
968  get(dnn::tau_emFraction) = getValueLinear(tau.emFraction_MVA(), -1, 1, false);
969  get(dnn::tau_inside_ecal_crack) = getValue(isInEcalCrack(tau.p4().eta()));
970  get(dnn::leadChargedCand_etaAtEcalEntrance_minus_tau_eta) =
971  getValueNorm(tau.etaAtEcalEntranceLeadChargedCand() - tau.p4().eta(), 0.0042f, 0.0323f);
972 
973  checkInputs(inputs, "tau_block", dnn::NumberOfInputs);
974  }
float tau_Eratio(const reco::PFTau &tau) const
return ratio of energy in ECAL over sum of energy in ECAL and HCAL
const bool disable_dxy_pca_
Definition: DeepTauId.cc:1702
static float getValueLinear(T value, float min_value, float max_value, bool positive)
Definition: DeepTauId.cc:664
static bool isInEcalCrack(double eta)
Definition: DeepTauId.cc:1676
TauIdMVAAuxiliaries clusterVariables
Definition: DeepTauId.cc:1706
static float getValue(T value)
Definition: DeepTauId.cc:658
float tau_pt_weighted_dphi_strip(const reco::PFTau &tau, int dm) const
static float getValueNorm(T value, float mean, float sigma, float n_sigmas_max=5)
Definition: DeepTauId.cc:675
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
float tau_pt_weighted_dr_signal(const reco::PFTau &tau, int dm) const
float tau_pt_weighted_dr_iso(const reco::PFTau &tau, int dm) const
std::shared_ptr< tensorflow::Tensor > tauBlockTensor_
Definition: DeepTauId.cc:1703
float tau_pt_weighted_deta_strip(const reco::PFTau &tau, int dm) const
void checkInputs(const tensorflow::Tensor &inputs, const char *block_name, int n_inputs, int n_eta=1, int n_phi=1) const
Definition: DeepTauId.cc:704
static bool calculateGottfriedJacksonAngleDifference(const pat::Tau &tau, double &gj_diff)
Definition: DeepTauId.cc:1649
static float pi
Definition: DeepTauId.cc:655
static float default_value
Definition: DeepTauId.cc:554
unsigned int tau_n_photons_total(const reco::PFTau &tau) const
return total number of pf photon candidates with pT>500 MeV, which are associated to signal ...
static void DeepTauId::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
inlinestatic

Definition at line 567 of file DeepTauId.cc.

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::add(), and AlCaHLTBitMon_QueryRunRegistry::string.

568  {
570  desc.add<edm::InputTag>("electrons", edm::InputTag("slimmedElectrons"));
571  desc.add<edm::InputTag>("muons", edm::InputTag("slimmedMuons"));
572  desc.add<edm::InputTag>("taus", edm::InputTag("slimmedTaus"));
573  desc.add<edm::InputTag>("pfcands", edm::InputTag("packedPFCandidates"));
574  desc.add<edm::InputTag>("vertices", edm::InputTag("offlineSlimmedPrimaryVertices"));
575  desc.add<edm::InputTag>("rho", edm::InputTag("fixedGridRhoAll"));
576  desc.add<std::vector<std::string>>("graph_file", {"RecoTauTag/TrainingFiles/data/DeepTauId/deepTau_2017v2p6_e6.pb"});
577  desc.add<bool>("mem_mapped", false);
578  desc.add<unsigned>("version", 2);
579  desc.add<int>("debug_level", 0);
580  desc.add<bool>("disable_dxy_pca", false);
581 
583  descWP.add<std::string>("VVVLoose", "0");
584  descWP.add<std::string>("VVLoose", "0");
585  descWP.add<std::string>("VLoose", "0");
586  descWP.add<std::string>("Loose", "0");
587  descWP.add<std::string>("Medium", "0");
588  descWP.add<std::string>("Tight", "0");
589  descWP.add<std::string>("VTight", "0");
590  descWP.add<std::string>("VVTight", "0");
591  descWP.add<std::string>("VVVTight", "0");
592  desc.add<edm::ParameterSetDescription>("VSeWP", descWP);
593  desc.add<edm::ParameterSetDescription>("VSmuWP", descWP);
594  desc.add<edm::ParameterSetDescription>("VSjetWP", descWP);
595  descriptions.add("DeepTau", desc);
596  }
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
template<typename Collection >
void DeepTauId::fillGrids ( const TauType tau,
const Collection &  objects,
CellGrid &  inner_grid,
CellGrid &  outer_grid 
)
inlineprivate

Definition at line 794 of file DeepTauId.cc.

References constexpr, reco::deltaPhi(), listHistos::grid, gen::n, GetRecoTauVFromDQM_MC_cff::obj, reco::LeafCandidate::polarP4(), and funct::pow().

795  {
796  static constexpr double outer_dR2 = 0.25;//0.5^2
797  const double inner_radius = getInnerSignalConeRadius(tau.polarP4().pt());
798  const double inner_dR2 = std::pow(inner_radius, 2);
799 
800  const auto addObject = [&](size_t n, double deta, double dphi, CellGrid& grid) {
801  const auto& obj = objects.at(n);
802  const CellObjectType obj_type = GetCellObjectType(obj);
803  if(obj_type == CellObjectType::Other) return;
804  CellIndex cell_index;
805  if(grid.tryGetCellIndex(deta, dphi, cell_index)) {
806  Cell& cell = grid[cell_index];
807  auto iter = cell.find(obj_type);
808  if(iter != cell.end()) {
809  const auto& prev_obj = objects.at(iter->second);
810  if(obj.polarP4().pt() > prev_obj.polarP4().pt())
811  iter->second = n;
812  } else {
813  cell[obj_type] = n;
814  }
815  }
816  };
817 
818  for(size_t n = 0; n < objects.size(); ++n) {
819  const auto& obj = objects.at(n);
820  const double deta = obj.polarP4().eta() - tau.polarP4().eta();
821  const double dphi = reco::deltaPhi(obj.polarP4().phi(), tau.polarP4().phi());
822  const double dR2 = std::pow(deta, 2) + std::pow(dphi, 2);
823  if(dR2 < inner_dR2)
824  addObject(n, deta, dphi, inner_grid);
825  if(dR2 < outer_dR2)
826  addObject(n, deta, dphi, outer_grid);
827  }
828  }
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:22
static double getInnerSignalConeRadius(double pt)
Definition: DeepTauId.cc:1641
#define constexpr
CellObjectType
Definition: DeepTauId.cc:457
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
static const pat::Electron* DeepTauId::findMatchedElectron ( const pat::Tau tau,
const pat::ElectronCollection electrons,
double  deltaR 
)
inlinestaticprivate

Definition at line 1682 of file DeepTauId.cc.

References deltaR(), reco::deltaR2(), reco::LeafCandidate::p4(), and reco::LeafCandidate::pt().

1684  {
1685  const double dR2 = deltaR*deltaR;
1686  const pat::Electron* matched_ele = nullptr;
1687  for(const auto& ele : electrons) {
1688  if(reco::deltaR2(tau.p4(), ele.p4()) < dR2 && (!matched_ele || matched_ele->pt() < ele.pt())) {
1689  matched_ele = &ele;
1690  }
1691  }
1692  return matched_ele;
1693  }
double pt() const final
transverse momentum
const LorentzVector & p4() const final
four-momentum Lorentz vector
Definition: LeafCandidate.h:99
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
Analysis-level electron class.
Definition: Electron.h:52
static double DeepTauId::getInnerSignalConeRadius ( double  pt)
inlinestaticprivate

Definition at line 1641 of file DeepTauId.cc.

References constexpr, SiStripPI::max, and cosmictrackSelector_cfi::min_pt.

1642  {
1643  static constexpr double min_pt = 30., min_radius = 0.05, cone_opening_coef = 3.;
1644  // This is equivalent of the original formula (std::max(std::min(0.1, 3.0/pt), 0.05)
1645  return std::max(cone_opening_coef / std::max(pt, min_pt), min_radius);
1646  }
#define constexpr
static const OutputCollection& DeepTauId::GetOutputs ( )
inlinestatic

Definition at line 556 of file DeepTauId.cc.

References constexpr, and Output.

557  {
558  static constexpr size_t e_index = 0, mu_index = 1, tau_index = 2, jet_index = 3;
559  static const OutputCollection outputs_ = {
560  { "VSe", Output({tau_index}, {e_index, tau_index}) },
561  { "VSmu", Output({tau_index}, {mu_index, tau_index}) },
562  { "VSjet", Output({tau_index}, {jet_index, tau_index}) },
563  };
564  return outputs_;
565  }
std::map< std::string, Output > OutputCollection
Definition: DeepTauBase.h:82
#define constexpr
OutputCollection outputs_
Definition: DeepTauBase.h:102
#define Output(cl)
Definition: vmac.h:194
void DeepTauId::getPartialPredictions ( tensorflow::Tensor &  convTensor,
bool  is_inner,
int  eta_index,
int  phi_index 
)
inlineprivate

Definition at line 830 of file DeepTauId.cc.

References tensorflow::run().

831  {
832  std::vector<tensorflow::Tensor> pred_vector;
833  if(is_inner) {
834  tensorflow::run(&(cache_->getSession("inner")),
835  { { "input_inner_egamma", *eGammaTensor_.at(is_inner) },
836  { "input_inner_muon", *muonTensor_.at(is_inner) },
837  { "input_inner_hadrons", *hadronsTensor_.at(is_inner) }, },
838  { "inner_all_dropout_4/Identity" }, &pred_vector);
839  } else {
840  tensorflow::run(&(cache_->getSession("outer")),
841  { { "input_outer_egamma", *eGammaTensor_.at(is_inner) },
842  { "input_outer_muon", *muonTensor_.at(is_inner) },
843  { "input_outer_hadrons", *hadronsTensor_.at(is_inner) }, },
844  { "outer_all_dropout_4/Identity" }, &pred_vector);
845  }
846  setCellConvFeatures(convTensor, pred_vector.at(0), eta_index, phi_index);
847  }
const DeepTauCache * cache_
Definition: DeepTauBase.h:103
std::array< std::shared_ptr< tensorflow::Tensor >, 2 > muonTensor_
Definition: DeepTauId.cc:1704
std::array< std::shared_ptr< tensorflow::Tensor >, 2 > hadronsTensor_
Definition: DeepTauId.cc:1704
std::array< std::shared_ptr< tensorflow::Tensor >, 2 > eGammaTensor_
Definition: DeepTauId.cc:1704
void setCellConvFeatures(tensorflow::Tensor &convTensor, const tensorflow::Tensor &features, int eta_index, int phi_index)
Definition: DeepTauId.cc:874
void run(Session *session, const NamedTensorList &inputs, const std::vector< std::string > &outputNames, const std::vector< std::string > &targetNodes, std::vector< Tensor > *outputs)
Definition: TensorFlow.cc:210
tensorflow::Session & getSession(const std::string &name="") const
Definition: DeepTauBase.h:49
tensorflow::Tensor DeepTauId::getPredictions ( edm::Event event,
const edm::EventSetup es,
edm::Handle< TauCollection taus 
)
inlineoverrideprivatevirtual

Implements deep_tau::DeepTauBase.

Definition at line 725 of file DeepTauId.cc.

References nano_cff::electrons, Exception, gen::k, extraflags_cff::muons, deep_tau::NumberOfOutputs, jets_cff::version, and electrons_cff::vertices.

727  {
729  event.getByToken(electrons_token_, electrons);
730 
732  event.getByToken(muons_token_, muons);
733 
735  event.getByToken(pfcandToken_, pfCands);
736 
738  event.getByToken(vtxToken_, vertices);
739 
741  event.getByToken(rho_token_, rho);
742 
743  tensorflow::Tensor predictions(tensorflow::DT_FLOAT, { static_cast<int>(taus->size()),
745  for(size_t tau_index = 0; tau_index < taus->size(); ++tau_index) {
746  std::vector<tensorflow::Tensor> pred_vector;
747  if(version == 1)
748  getPredictionsV1(taus->at(tau_index), *electrons, *muons, pred_vector);
749  else if(version == 2)
750  getPredictionsV2(taus->at(tau_index), *electrons, *muons, *pfCands, vertices->at(0), *rho, pred_vector);
751  else
752  throw cms::Exception("DeepTauId") << "version " << version << " is not supported.";
753  for(int k = 0; k < deep_tau::NumberOfOutputs; ++k) {
754  const float pred = pred_vector[0].flat<float>()(k);
755  if(!(pred >= 0 && pred <= 1))
756  throw cms::Exception("DeepTauId") << "invalid prediction = " << pred << " for tau_index = "
757  << tau_index << ", pred_index = " << k;
758  predictions.matrix<float>()(tau_index, k) = pred;
759  }
760  }
761  return predictions;
762  }
edm::EDGetTokenT< ElectronCollection > electrons_token_
Definition: DeepTauId.cc:1696
int NumberOfOutputs
Definition: DeepTauId.cc:13
void getPredictionsV2(const TauType &tau, const pat::ElectronCollection &electrons, const pat::MuonCollection &muons, const pat::PackedCandidateCollection &pfCands, const reco::Vertex &pv, double rho, std::vector< tensorflow::Tensor > &pred_vector)
Definition: DeepTauId.cc:771
void getPredictionsV1(const TauType &tau, const pat::ElectronCollection &electrons, const pat::MuonCollection &muons, std::vector< tensorflow::Tensor > &pred_vector)
Definition: DeepTauId.cc:764
const unsigned version
Definition: DeepTauId.cc:1700
int k[5][pyjets_maxn]
edm::EDGetTokenT< MuonCollection > muons_token_
Definition: DeepTauId.cc:1697
edm::EDGetTokenT< double > rho_token_
Definition: DeepTauId.cc:1698
edm::EDGetTokenT< pat::PackedCandidateCollection > pfcandToken_
Definition: DeepTauBase.h:99
edm::EDGetTokenT< reco::VertexCollection > vtxToken_
Definition: DeepTauBase.h:100
void DeepTauId::getPredictionsV1 ( const TauType tau,
const pat::ElectronCollection electrons,
const pat::MuonCollection muons,
std::vector< tensorflow::Tensor > &  pred_vector 
)
inlineprivate

Definition at line 764 of file DeepTauId.cc.

References nano_cff::electrons, PatBasicFWLiteJetAnalyzer_Selector_cfg::inputs, extraflags_cff::muons, tensorflow::run(), and metsig::tau.

766  {
767  const tensorflow::Tensor& inputs = createInputsV1<dnn_inputs_2017v1>(tau, electrons, muons);
768  tensorflow::run(&(cache_->getSession()), { { input_layer_, inputs } }, { output_layer_ }, &pred_vector);
769  }
const DeepTauCache * cache_
Definition: DeepTauBase.h:103
std::string output_layer_
Definition: DeepTauId.cc:1699
std::string input_layer_
Definition: DeepTauId.cc:1699
void run(Session *session, const NamedTensorList &inputs, const std::vector< std::string > &outputNames, const std::vector< std::string > &targetNodes, std::vector< Tensor > *outputs)
Definition: TensorFlow.cc:210
tensorflow::Session & getSession(const std::string &name="") const
Definition: DeepTauBase.h:49
void DeepTauId::getPredictionsV2 ( const TauType tau,
const pat::ElectronCollection electrons,
const pat::MuonCollection muons,
const pat::PackedCandidateCollection pfCands,
const reco::Vertex pv,
double  rho,
std::vector< tensorflow::Tensor > &  pred_vector 
)
inlineprivate

Definition at line 771 of file DeepTauId.cc.

References tensorflow::run().

774  {
775  CellGrid inner_grid(dnn_inputs_2017_v2::number_of_inner_cell, dnn_inputs_2017_v2::number_of_inner_cell,
776  0.02, 0.02);
777  CellGrid outer_grid(dnn_inputs_2017_v2::number_of_outer_cell, dnn_inputs_2017_v2::number_of_outer_cell,
778  0.05, 0.05);
779  fillGrids(tau, electrons, inner_grid, outer_grid);
780  fillGrids(tau, muons, inner_grid, outer_grid);
781  fillGrids(tau, pfCands, inner_grid, outer_grid);
782 
784  createConvFeatures(tau, pv, rho, electrons, muons, pfCands, inner_grid, true);
785  createConvFeatures(tau, pv, rho, electrons, muons, pfCands, outer_grid, false);
786 
787  tensorflow::run(&(cache_->getSession("core")),
788  { { "input_tau", *tauBlockTensor_ },
789  { "input_inner", *convTensor_.at(true)}, { "input_outer", *convTensor_.at(false) } },
790  { "main_output/Softmax" }, &pred_vector);
791  }
void createConvFeatures(const TauType &tau, const reco::Vertex &pv, double rho, const pat::ElectronCollection &electrons, const pat::MuonCollection &muons, const pat::PackedCandidateCollection &pfCands, const CellGrid &grid, bool is_inner)
Definition: DeepTauId.cc:849
const DeepTauCache * cache_
Definition: DeepTauBase.h:103
void createTauBlockInputs(const TauType &tau, const reco::Vertex &pv, double rho)
Definition: DeepTauId.cc:881
void fillGrids(const TauType &tau, const Collection &objects, CellGrid &inner_grid, CellGrid &outer_grid)
Definition: DeepTauId.cc:794
std::shared_ptr< tensorflow::Tensor > tauBlockTensor_
Definition: DeepTauId.cc:1703
std::array< std::shared_ptr< tensorflow::Tensor >, 2 > convTensor_
Definition: DeepTauId.cc:1704
void run(Session *session, const NamedTensorList &inputs, const std::vector< std::string > &outputNames, const std::vector< std::string > &targetNodes, std::vector< Tensor > *outputs)
Definition: TensorFlow.cc:210
tensorflow::Session & getSession(const std::string &name="") const
Definition: DeepTauBase.h:49
template<typename T >
static float DeepTauId::getValue ( T  value)
inlinestaticprivate

Definition at line 658 of file DeepTauId.cc.

References f, and relativeConstraints::value.

659  {
660  return std::isnormal(value) ? static_cast<float>(value) : 0.f;
661  }
double f[11][100]
Definition: value.py:1
template<typename T >
static float DeepTauId::getValueLinear ( T  value,
float  min_value,
float  max_value,
bool  positive 
)
inlinestaticprivate

Definition at line 664 of file DeepTauId.cc.

References reco::JetExtendedAssociation::getValue(), and hcaldqm::quantity::min_value.

665  {
666  const float fixed_value = getValue(value);
667  const float clamped_value = std::clamp(fixed_value, min_value, max_value);
668  float transformed_value = (clamped_value - min_value) / (max_value - min_value);
669  if(!positive)
670  transformed_value = transformed_value * 2 - 1;
671  return transformed_value;
672  }
const std::map< ValueQuantityType, double > min_value
static float getValue(T value)
Definition: DeepTauId.cc:658
Definition: value.py:1
const std::map< ValueQuantityType, double > max_value
template<typename T >
static float DeepTauId::getValueNorm ( T  value,
float  mean,
float  sigma,
float  n_sigmas_max = 5 
)
inlinestaticprivate

Definition at line 675 of file DeepTauId.cc.

References reco::JetExtendedAssociation::getValue(), and SiStripPI::mean.

676  {
677  const float fixed_value = getValue(value);
678  const float norm_value = (fixed_value - mean) / sigma;
679  return std::clamp(norm_value, -n_sigmas_max, n_sigmas_max);
680  }
static float getValue(T value)
Definition: DeepTauId.cc:658
Definition: value.py:1
static void DeepTauId::globalEndJob ( const deep_tau::DeepTauCache cache_)
inlinestatic

Definition at line 650 of file DeepTauId.cc.

References deep_tau::DeepTauBase::globalEndJob().

651  {
652  return DeepTauBase::globalEndJob(cache_);
653  }
static std::unique_ptr<deep_tau::DeepTauCache> DeepTauId::initializeGlobalCache ( const edm::ParameterSet cfg)
inlinestatic

Definition at line 645 of file DeepTauId.cc.

References deep_tau::DeepTauBase::initializeGlobalCache().

646  {
647  return DeepTauBase::initializeGlobalCache(cfg);
648  }
static bool DeepTauId::isInEcalCrack ( double  eta)
inlinestaticprivate

Definition at line 1676 of file DeepTauId.cc.

References funct::abs().

1677  {
1678  const double abs_eta = std::abs(eta);
1679  return abs_eta > 1.46 && abs_eta < 1.558;
1680  }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
template<typename CandidateCollection >
static void DeepTauId::processIsolationPFComponents ( const pat::Tau tau,
const CandidateCollection &  candidates,
LorentzVectorXYZ p4,
float &  pt,
float &  d_eta,
float &  d_phi,
float &  m,
float &  n 
)
inlinestaticprivate

Definition at line 1623 of file DeepTauId.cc.

References particleFlow_cfi::dEta, particleFlow_cfi::dPhi, gen::n, and reco::LeafCandidate::p4().

1626  {
1627  p4 = LorentzVectorXYZ(0, 0, 0, 0);
1628  n = 0;
1629 
1630  for(const auto& cand : candidates) {
1631  p4 += cand->p4();
1632  ++n;
1633  }
1634 
1635  pt = n != 0 ? p4.Pt() : default_value;
1636  d_eta = n != 0 ? dEta(p4, tau.p4()) : default_value;
1637  d_phi = n != 0 ? dPhi(p4, tau.p4()) : default_value;
1638  m = n != 0 ? p4.mass() : default_value;
1639  }
double p4[4]
Definition: TauolaWrapper.h:92
const LorentzVector & p4() const final
four-momentum Lorentz vector
Definition: LeafCandidate.h:99
static float default_value
Definition: DeepTauId.cc:554
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double >> LorentzVectorXYZ
Definition: DeepTauBase.h:67
template<typename CandidateCollection >
static void DeepTauId::processSignalPFComponents ( const pat::Tau 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 1587 of file DeepTauId.cc.

References reco::deltaR(), particleFlow_cfi::dEta, particleFlow_cfi::dPhi, PFRecoTauDiscriminationAgainstElectronDeadECAL_cfi::dR, pat::Tau::leadChargedHadrCand(), reco::LeafCandidate::p4(), and reco::LeafCandidate::pt().

1592  {
1593  p4_inner = LorentzVectorXYZ(0, 0, 0, 0);
1594  p4_outer = LorentzVectorXYZ(0, 0, 0, 0);
1595  n_inner = 0;
1596  n_outer = 0;
1597 
1598  const double innerSigCone_radius = getInnerSignalConeRadius(tau.pt());
1599  for(const auto& cand : candidates) {
1600  const double dR = reco::deltaR(cand->p4(), tau.leadChargedHadrCand()->p4());
1601  const bool isInside_innerSigCone = dR < innerSigCone_radius;
1602  if(isInside_innerSigCone) {
1603  p4_inner += cand->p4();
1604  ++n_inner;
1605  } else {
1606  p4_outer += cand->p4();
1607  ++n_outer;
1608  }
1609  }
1610 
1611  pt_inner = n_inner != 0 ? p4_inner.Pt() : default_value;
1612  dEta_inner = n_inner != 0 ? dEta(p4_inner, tau.p4()) : default_value;
1613  dPhi_inner = n_inner != 0 ? dPhi(p4_inner, tau.p4()) : default_value;
1614  m_inner = n_inner != 0 ? p4_inner.mass() : default_value;
1615 
1616  pt_outer = n_outer != 0 ? p4_outer.Pt() : default_value;
1617  dEta_outer = n_outer != 0 ? dEta(p4_outer, tau.p4()) : default_value;
1618  dPhi_outer = n_outer != 0 ? dPhi(p4_outer, tau.p4()) : default_value;
1619  m_outer = n_outer != 0 ? p4_outer.mass() : default_value;
1620  }
static double getInnerSignalConeRadius(double pt)
Definition: DeepTauId.cc:1641
double pt() const final
transverse momentum
const LorentzVector & p4() const final
four-momentum Lorentz vector
Definition: LeafCandidate.h:99
const reco::CandidatePtr leadChargedHadrCand() const
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:28
static float default_value
Definition: DeepTauId.cc:554
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double >> LorentzVectorXYZ
Definition: DeepTauBase.h:67
void DeepTauId::setCellConvFeatures ( tensorflow::Tensor &  convTensor,
const tensorflow::Tensor &  features,
int  eta_index,
int  phi_index 
)
inlineprivate

Definition at line 874 of file DeepTauId.cc.

References gen::n.

876  {
877  for(int n = 0; n < dnn_inputs_2017_v2::number_of_conv_features; ++n)
878  convTensor.tensor<float, 4>()(0, eta_index, phi_index, n) = features.tensor<float, 4>()(0, 0, 0, n);
879  }

Member Data Documentation

TauIdMVAAuxiliaries DeepTauId::clusterVariables
private

Definition at line 1706 of file DeepTauId.cc.

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

Definition at line 1704 of file DeepTauId.cc.

const int DeepTauId::debug_level
private

Definition at line 1701 of file DeepTauId.cc.

float DeepTauId::default_value = -999.
static

Definition at line 554 of file DeepTauId.cc.

const bool DeepTauId::disable_dxy_pca_
private

Definition at line 1702 of file DeepTauId.cc.

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

Definition at line 1704 of file DeepTauId.cc.

edm::EDGetTokenT<ElectronCollection> DeepTauId::electrons_token_
private

Definition at line 1696 of file DeepTauId.cc.

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

Definition at line 1704 of file DeepTauId.cc.

std::string DeepTauId::input_layer_
private

Definition at line 1699 of file DeepTauId.cc.

edm::EDGetTokenT<MuonCollection> DeepTauId::muons_token_
private

Definition at line 1697 of file DeepTauId.cc.

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

Definition at line 1704 of file DeepTauId.cc.

std::string DeepTauId::output_layer_
private

Definition at line 1699 of file DeepTauId.cc.

float DeepTauId::pi = M_PI
staticprivate

Definition at line 655 of file DeepTauId.cc.

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

Definition at line 1698 of file DeepTauId.cc.

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

Definition at line 1703 of file DeepTauId.cc.

const unsigned DeepTauId::version
private
std::array<std::shared_ptr<tensorflow::Tensor>, 2> DeepTauId::zeroOutputTensor_
private

Definition at line 1704 of file DeepTauId.cc.