CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes
L2TauNNProducer Class Reference
Inheritance diagram for L2TauNNProducer:
edm::stream::EDProducer< edm::GlobalCache< L2TauNNProducerCacheData > >

Classes

struct  caloRecHitCollections
 
struct  InputDescTau
 

Public Member Functions

 L2TauNNProducer (const edm::ParameterSet &, const L2TauNNProducerCacheData *)
 
- Public Member Functions inherited from edm::stream::EDProducer< edm::GlobalCache< L2TauNNProducerCacheData > >
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &)
 
static void globalEndJob (L2TauNNProducerCacheData *)
 
static std::unique_ptr
< L2TauNNProducerCacheData
initializeGlobalCache (const edm::ParameterSet &)
 

Static Public Attributes

static constexpr float dEta_width = 2 * L2TauTagNNv1::dR_max / static_cast<float>(L2TauTagNNv1::nCellEta)
 
static constexpr float dPhi_width = 2 * L2TauTagNNv1::dR_max / static_cast<float>(L2TauTagNNv1::nCellPhi)
 
static constexpr float dR2_max = L2TauTagNNv1::dR_max * L2TauTagNNv1::dR_max
 

Private Member Functions

void checknan (tensorflow::Tensor &tensor, int debugLevel)
 
void fillCaloRecHits (tensorflow::Tensor &cellGridMatrix, const std::vector< l1t::TauRef > &allTaus, const caloRecHitCollections &caloRecHits)
 
void fillL1TauVars (tensorflow::Tensor &cellGridMatrix, const std::vector< l1t::TauRef > &allTaus)
 
void fillPatatracks (tensorflow::Tensor &cellGridMatrix, const std::vector< l1t::TauRef > &allTaus, const pixelTrack::TrackSoA &patatracks_tsoa, const ZVertexSoA &patavtx_soa, const reco::BeamSpot &beamspot, const MagneticField *magfi)
 
template<typename VPos , typename LVec >
std::tuple< float, float, int,
int > 
getEtaPhiIndices (const VPos &position, const LVec &tau_p4)
 
template<typename LVec >
std::tuple< float, float, int,
int > 
getEtaPhiIndices (float eta, float phi, const LVec &tau_p4)
 
std::vector< float > getTauScore (const tensorflow::Tensor &cellGridMatrix)
 
std::pair< float, float > impactParameter (int it, const pixelTrack::TrackSoA &patatracks_tsoa, float patatrackPhi, const reco::BeamSpot &beamspot, const MagneticField *magfi)
 
void produce (edm::Event &event, const edm::EventSetup &eventsetup) override
 
std::vector< int > selectGoodVertices (const ZVertexSoA &patavtx_soa, const pixelTrack::TrackSoA &patatracks_tsoa, const std::vector< int > &TrackGood)
 
void standardizeTensor (tensorflow::Tensor &tensor)
 

Private Attributes

const edm::EDGetTokenT
< reco::BeamSpot
beamSpotToken_
 
const edm::ESGetToken
< MagneticField,
IdealMagneticFieldRecord
bFieldToken_
 
const int debugLevel_
 
const edm::EDGetTokenT
< EcalRecHitCollection
ebToken_
 
const edm::EDGetTokenT
< EcalRecHitCollection
eeToken_
 
const double fractionSumPt2_
 
const edm::ESGetToken
< CaloGeometry,
CaloGeometryRecord
geometryToken_
 
const edm::EDGetTokenT
< HBHERecHitCollection
hbheToken_
 
const edm::EDGetTokenT
< HORecHitCollection
hoToken_
 
std::string inputTensorName_
 
std::vector< InputDescTauL1TauDesc_
 
const L2TauNNProducerCacheDataL2cacheData_
 
const unsigned int maxVtx_
 
const double minSumPt2_
 
std::string outputTensorName_
 
const edm::EDGetTokenT
< PixelTrackHeterogeneous
pataTracksToken_
 
const edm::EDGetTokenT
< ZVertexHeterogeneous
pataVerticesToken_
 
const edm::EDGetTokenT
< trigger::TriggerFilterObjectWithRefs
tauTriggerToken_
 
const double trackChi2Max_
 
const double trackPtMax_
 
const double trackPtMin_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer< edm::GlobalCache< L2TauNNProducerCacheData > >
using CacheTypes = CacheContexts< T...>
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T...>
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

Detailed Description

Definition at line 147 of file L2TauTagNNProducer.cc.

Constructor & Destructor Documentation

L2TauNNProducer::L2TauNNProducer ( const edm::ParameterSet cfg,
const L2TauNNProducerCacheData cacheData 
)
explicit

Definition at line 286 of file L2TauTagNNProducer.cc.

References L2TauNNProducer::InputDescTau::CollectionName, submitPVResolutionJobs::desc, Exception, edm::ParameterSet::getParameter(), L2TauNNProducerCacheData::graphDef, inputTensorName_, L2TauNNProducer::InputDescTau::inputToken_, L1TauDesc_, L2cacheData_, mergeVDriftHistosByStation::name, outputTensorName_, and AlCaHLTBitMon_QueryRunRegistry::string.

287  : debugLevel_(cfg.getParameter<int>("debugLevel")),
288  hbheToken_(consumes<HBHERecHitCollection>(cfg.getParameter<edm::InputTag>("hbheInput"))),
289  hoToken_(consumes<HORecHitCollection>(cfg.getParameter<edm::InputTag>("hoInput"))),
290  ebToken_(consumes<EcalRecHitCollection>(cfg.getParameter<edm::InputTag>("ebInput"))),
291  eeToken_(consumes<EcalRecHitCollection>(cfg.getParameter<edm::InputTag>("eeInput"))),
292  geometryToken_(esConsumes<CaloGeometry, CaloGeometryRecord>()),
293  bFieldToken_(esConsumes<MagneticField, IdealMagneticFieldRecord>()),
294  pataVerticesToken_(consumes<ZVertexHeterogeneous>(cfg.getParameter<edm::InputTag>("pataVertices"))),
295  pataTracksToken_(consumes<PixelTrackHeterogeneous>(cfg.getParameter<edm::InputTag>("pataTracks"))),
296  beamSpotToken_(consumes<reco::BeamSpot>(cfg.getParameter<edm::InputTag>("BeamSpot"))),
297  maxVtx_(cfg.getParameter<uint>("maxVtx")),
298  fractionSumPt2_(cfg.getParameter<double>("fractionSumPt2")),
299  minSumPt2_(cfg.getParameter<double>("minSumPt2")),
300  trackPtMin_(cfg.getParameter<double>("track_pt_min")),
301  trackPtMax_(cfg.getParameter<double>("track_pt_max")),
302  trackChi2Max_(cfg.getParameter<double>("track_chi2_max")) {
303  if (cacheData->graphDef == nullptr) {
304  throw cms::Exception("InvalidCacheData") << "Invalid Cache Data.";
305  }
306  inputTensorName_ = cacheData->graphDef->node(0).name();
307  outputTensorName_ = cacheData->graphDef->node(cacheData->graphDef->node_size() - 1).name();
308  L2cacheData_ = cacheData;
309  std::vector<edm::ParameterSet> L1TauCollections = cfg.getParameter<std::vector<edm::ParameterSet>>("L1Taus");
310  L1TauDesc_.reserve(L1TauCollections.size());
311  for (const auto& l1TauInput : L1TauCollections) {
312  InputDescTau toInsert;
313  toInsert.CollectionName = l1TauInput.getParameter<std::string>("L1CollectionName");
314  toInsert.inputToken_ =
315  consumes<trigger::TriggerFilterObjectWithRefs>(l1TauInput.getParameter<edm::InputTag>("L1TauTrigger"));
316  L1TauDesc_.push_back(toInsert);
317  }
318  for (const auto& desc : L1TauDesc_)
319  produces<std::vector<float>>(desc.CollectionName);
320 }
std::string inputTensorName_
const edm::EDGetTokenT< PixelTrackHeterogeneous > pataTracksToken_
const edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
const edm::EDGetTokenT< HORecHitCollection > hoToken_
std::vector< InputDescTau > L1TauDesc_
const unsigned int maxVtx_
const double minSumPt2_
const double trackPtMax_
const edm::EDGetTokenT< ZVertexHeterogeneous > pataVerticesToken_
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > bFieldToken_
const double trackChi2Max_
const edm::EDGetTokenT< HBHERecHitCollection > hbheToken_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
const double trackPtMin_
std::string outputTensorName_
const double fractionSumPt2_
tensorflow::GraphDef * graphDef
const L2TauNNProducerCacheData * L2cacheData_
const edm::EDGetTokenT< EcalRecHitCollection > eeToken_
const edm::EDGetTokenT< EcalRecHitCollection > ebToken_
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > geometryToken_

Member Function Documentation

void L2TauNNProducer::checknan ( tensorflow::Tensor &  tensor,
int  debugLevel 
)
private

Definition at line 322 of file L2TauTagNNProducer.cc.

References ztail::d, Exception, input, edm::isNotFinite(), and L2TauTagNNv1::varNameMap.

Referenced by produce().

322  {
324  std::vector<int> tensor_shape(tensor.shape().dims());
325  for (int d = 0; d < tensor.shape().dims(); d++) {
326  tensor_shape.at(d) = tensor.shape().dim_size(d);
327  }
328  if (tensor_shape.size() != 4) {
329  throw cms::Exception("InvalidTensor") << "Tensor shape does not have 4 dimensions!";
330  }
331  for (int tau_idx = 0; tau_idx < tensor_shape.at(0); tau_idx++) {
332  for (int phi_idx = 0; phi_idx < tensor_shape.at(1); phi_idx++) {
333  for (int eta_idx = 0; eta_idx < tensor_shape.at(2); eta_idx++) {
334  for (int var_idx = 0; var_idx < tensor_shape.at(3); var_idx++) {
335  auto getCell = [&](NNInputs input) -> float& {
336  return getCellImpl(tensor, tau_idx, phi_idx, eta_idx, input);
337  };
338  auto nonstd_var = getCell(static_cast<NNInputs>(var_idx));
339  if (edm::isNotFinite(nonstd_var)) {
340  edm::LogWarning("InputVar") << "var is nan \nvar name= "
341  << L2TauTagNNv1::varNameMap.at(static_cast<L2TauTagNNv1::NNInputs>(var_idx))
342  << "\t var_idx = " << var_idx << "\t eta_idx = " << eta_idx
343  << "\t phi_idx = " << phi_idx << "\t tau_idx = " << tau_idx << std::endl;
344  if (debugLevel > 2) {
345  edm::LogWarning("InputVar") << "other vars in same cell \n";
346  if (var_idx + 1 < tensor_shape.at(3))
347  edm::LogWarning("InputVar") << L2TauTagNNv1::varNameMap.at(static_cast<NNInputs>(var_idx + 1))
348  << "\t = " << getCell(static_cast<NNInputs>(var_idx + 1)) << std::endl;
349  if (var_idx + 2 < tensor_shape.at(3))
350  edm::LogWarning("InputVar") << L2TauTagNNv1::varNameMap.at(static_cast<NNInputs>(var_idx + 2))
351  << "\t = " << getCell(static_cast<NNInputs>(var_idx + 2)) << std::endl;
352  if (var_idx + 3 < tensor_shape.at(3))
353  edm::LogWarning("InputVar") << L2TauTagNNv1::varNameMap.at(static_cast<NNInputs>(var_idx + 3))
354  << "\t = " << getCell(static_cast<NNInputs>(var_idx + 3)) << std::endl;
355  if (var_idx + 4 < tensor_shape.at(3))
356  edm::LogWarning("InputVar") << L2TauTagNNv1::varNameMap.at(static_cast<NNInputs>(var_idx + 4))
357  << "\t = " << getCell(static_cast<NNInputs>(var_idx + 4)) << std::endl;
358  }
359  }
360  }
361  }
362  }
363  }
364 }
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
static std::string const input
Definition: EdmProvDump.cc:47
tuple d
Definition: ztail.py:151
const std::map< NNInputs, std::string > varNameMap
Log< level::Warning, false > LogWarning
void L2TauNNProducer::fillCaloRecHits ( tensorflow::Tensor &  cellGridMatrix,
const std::vector< l1t::TauRef > &  allTaus,
const caloRecHitCollections caloRecHits 
)
private

Definition at line 431 of file L2TauTagNNProducer.cc.

References reco::deltaR2(), dR2_max, L2TauNNProducer::caloRecHitCollections::eb, L2TauNNProducer::caloRecHitCollections::ee, L2TauNNProducer::caloRecHitCollections::geometry, getEtaPhiIndices(), CaloGeometry::getGeometry(), L2TauNNProducer::caloRecHitCollections::hbhe, L2TauNNProducer::caloRecHitCollections::ho, input, L2TauTagNNv1::nCellEta, L2TauTagNNv1::nCellPhi, and position.

Referenced by produce().

433  {
435  const int nTaus = static_cast<int>(allTaus.size());
436  float deta, dphi;
437  int eta_idx = 0;
438  int phi_idx = 0;
439  int tau_idx = 0;
440 
441  auto getCell = [&](NNInputs input) -> float& {
442  return getCellImpl(cellGridMatrix, tau_idx, phi_idx, eta_idx, input);
443  };
444  for (tau_idx = 0; tau_idx < nTaus; tau_idx++) {
445  // calorechit_EE
446  for (const auto& caloRecHit_ee : *caloRecHits.ee) {
447  if (caloRecHit_ee.energy() <= 0)
448  continue;
449  const auto& position = caloRecHits.geometry->getGeometry(caloRecHit_ee.id())->getPosition();
450  const float eeCalEn = caloRecHit_ee.energy();
451  const float eeCalChi2 = caloRecHit_ee.chi2();
452  if (reco::deltaR2(position, allTaus[tau_idx]->polarP4()) < dR2_max) {
453  std::tie(deta, dphi, eta_idx, phi_idx) = getEtaPhiIndices(position, allTaus[tau_idx]->polarP4());
454  getCell(NNInputs::EcalEnergySum) += eeCalEn;
455  getCell(NNInputs::EcalSize) += 1.;
456  getCell(NNInputs::EcalEnergyStdDev) += eeCalEn * eeCalEn;
457  getCell(NNInputs::EcalDeltaEta) += deta * eeCalEn;
458  getCell(NNInputs::EcalDeltaPhi) += dphi * eeCalEn;
459  if (eeCalChi2 >= 0) {
460  getCell(NNInputs::EcalChi2) += eeCalChi2 * eeCalEn;
461  getCell(NNInputs::EcalEnergySumForPositiveChi2) += eeCalEn;
462  getCell(NNInputs::EcalSizeForPositiveChi2) += 1.;
463  }
464  }
465  }
466 
467  // calorechit_EB
468  for (const auto& caloRecHit_eb : *caloRecHits.eb) {
469  if (caloRecHit_eb.energy() <= 0)
470  continue;
471  const auto& position = caloRecHits.geometry->getGeometry(caloRecHit_eb.id())->getPosition();
472  const float ebCalEn = caloRecHit_eb.energy();
473  const float ebCalChi2 = caloRecHit_eb.chi2();
474  if (reco::deltaR2(position, allTaus[tau_idx]->polarP4()) < dR2_max) {
475  std::tie(deta, dphi, eta_idx, phi_idx) = getEtaPhiIndices(position, allTaus[tau_idx]->polarP4());
476  getCell(NNInputs::EcalEnergySum) += ebCalEn;
477  getCell(NNInputs::EcalSize) += 1.;
478  getCell(NNInputs::EcalEnergyStdDev) += ebCalEn * ebCalEn;
479  getCell(NNInputs::EcalDeltaEta) += deta * ebCalEn;
480  getCell(NNInputs::EcalDeltaPhi) += dphi * ebCalEn;
481  if (ebCalChi2 >= 0) {
482  getCell(NNInputs::EcalChi2) += ebCalChi2 * ebCalEn;
483  getCell(NNInputs::EcalEnergySumForPositiveChi2) += ebCalEn;
484  getCell(NNInputs::EcalSizeForPositiveChi2) += 1.;
485  }
486  }
487  }
488 
489  // calorechit_HBHE
490  for (const auto& caloRecHit_hbhe : *caloRecHits.hbhe) {
491  if (caloRecHit_hbhe.energy() <= 0)
492  continue;
493  const auto& position = caloRecHits.geometry->getGeometry(caloRecHit_hbhe.id())->getPosition();
494  const float hbheCalEn = caloRecHit_hbhe.energy();
495  const float hbheCalChi2 = caloRecHit_hbhe.chi2();
496  if (reco::deltaR2(position, allTaus[tau_idx]->polarP4()) < dR2_max) {
497  std::tie(deta, dphi, eta_idx, phi_idx) = getEtaPhiIndices(position, allTaus[tau_idx]->polarP4());
498  getCell(NNInputs::HcalEnergySum) += hbheCalEn;
499  getCell(NNInputs::HcalEnergyStdDev) += hbheCalEn * hbheCalEn;
500  getCell(NNInputs::HcalSize) += 1.;
501  getCell(NNInputs::HcalDeltaEta) += deta * hbheCalEn;
502  getCell(NNInputs::HcalDeltaPhi) += dphi * hbheCalEn;
503  if (hbheCalChi2 >= 0) {
504  getCell(NNInputs::HcalChi2) += hbheCalChi2 * hbheCalEn;
505  getCell(NNInputs::HcalEnergySumForPositiveChi2) += hbheCalEn;
506  getCell(NNInputs::HcalSizeForPositiveChi2) += 1.;
507  }
508  }
509  }
510 
511  // calorechit_HO
512  for (const auto& caloRecHit_ho : *caloRecHits.ho) {
513  if (caloRecHit_ho.energy() <= 0)
514  continue;
515  const auto& position = caloRecHits.geometry->getGeometry(caloRecHit_ho.id())->getPosition();
516  const float hoCalEn = caloRecHit_ho.energy();
517  if (reco::deltaR2(position, allTaus[tau_idx]->polarP4()) < dR2_max) {
518  std::tie(deta, dphi, eta_idx, phi_idx) = getEtaPhiIndices(position, allTaus[tau_idx]->polarP4());
519  getCell(NNInputs::HcalEnergySum) += hoCalEn;
520  getCell(NNInputs::HcalEnergyStdDev) += hoCalEn * hoCalEn;
521  getCell(NNInputs::HcalSize) += 1.;
522  getCell(NNInputs::HcalDeltaEta) += deta * hoCalEn;
523  getCell(NNInputs::HcalDeltaPhi) += dphi * hoCalEn;
524  }
525  }
526 
527  // normalize to sum and define stdDev
528  for (eta_idx = 0; eta_idx < L2TauTagNNv1::nCellEta; eta_idx++) {
529  for (phi_idx = 0; phi_idx < L2TauTagNNv1::nCellPhi; phi_idx++) {
530  /* normalize eCal vars*/
531  if (getCell(NNInputs::EcalEnergySum) > 0.) {
532  getCell(NNInputs::EcalDeltaEta) /= getCell(NNInputs::EcalEnergySum);
533  getCell(NNInputs::EcalDeltaPhi) /= getCell(NNInputs::EcalEnergySum);
534  }
535  if (getCell(NNInputs::EcalEnergySumForPositiveChi2) > 0.) {
536  getCell(NNInputs::EcalChi2) /= getCell(NNInputs::EcalEnergySumForPositiveChi2);
537  }
538  if (getCell(NNInputs::EcalSize) > 1.) {
539  // (stdDev - (enSum*enSum)/size) / (size-1)
540  getCell(NNInputs::EcalEnergyStdDev) =
541  (getCell(NNInputs::EcalEnergyStdDev) -
542  (getCell(NNInputs::EcalEnergySum) * getCell(NNInputs::EcalEnergySum)) / getCell(NNInputs::EcalSize)) /
543  (getCell(NNInputs::EcalSize) - 1);
544  } else {
545  getCell(NNInputs::EcalEnergyStdDev) = 0.;
546  }
547  /* normalize hCal Vars */
548  if (getCell(NNInputs::HcalEnergySum) > 0.) {
549  getCell(NNInputs::HcalDeltaEta) /= getCell(NNInputs::HcalEnergySum);
550  getCell(NNInputs::HcalDeltaPhi) /= getCell(NNInputs::HcalEnergySum);
551  }
552  if (getCell(NNInputs::HcalEnergySumForPositiveChi2) > 0.) {
553  getCell(NNInputs::HcalChi2) /= getCell(NNInputs::HcalEnergySumForPositiveChi2);
554  }
555  if (getCell(NNInputs::HcalSize) > 1.) {
556  // (stdDev - (enSum*enSum)/size) / (size-1)
557  getCell(NNInputs::HcalEnergyStdDev) =
558  (getCell(NNInputs::HcalEnergyStdDev) -
559  (getCell(NNInputs::HcalEnergySum) * getCell(NNInputs::HcalEnergySum)) / getCell(NNInputs::HcalSize)) /
560  (getCell(NNInputs::HcalSize) - 1);
561  } else {
562  getCell(NNInputs::HcalEnergyStdDev) = 0.;
563  }
564  }
565  }
566  }
567 }
std::tuple< float, float, int, int > getEtaPhiIndices(const VPos &position, const LVec &tau_p4)
static std::string const input
Definition: EdmProvDump.cc:47
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
static constexpr float dR2_max
constexpr int nCellEta
static int position[264][3]
Definition: ReadPGInfo.cc:289
constexpr int nCellPhi
void L2TauNNProducer::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 254 of file L2TauTagNNProducer.cc.

References edm::ParameterSetDescription::add(), edm::ParameterSet::addParameter(), edm::ParameterSetDescription::addVPSet(), edm::ConfigurationDescriptions::addWithDefaultLabel(), submitPVResolutionJobs::desc, HLT_FULL_cff::InputTag, edm::ParameterDescriptionNode::setComment(), AlCaHLTBitMon_QueryRunRegistry::string, and parallelization::uint().

254  {
256  desc.add<int>("debugLevel", 0)->setComment("set debug level for printing out info");
257  edm::ParameterSetDescription l1TausPset;
258  l1TausPset.add<std::string>("L1CollectionName", "DoubleTau")->setComment("Name of collections");
259  l1TausPset.add<edm::InputTag>("L1TauTrigger", edm::InputTag("hltL1sDoubleTauBigOR"))
260  ->setComment("Which trigger should the L1 Taus collection pass");
261  edm::ParameterSet l1TausPSetDefault;
262  l1TausPSetDefault.addParameter<std::string>("L1CollectionName", "DoubleTau");
263  l1TausPSetDefault.addParameter<edm::InputTag>("L1TauTrigger", edm::InputTag("hltL1sDoubleTauBigOR"));
264  desc.addVPSet("L1Taus", l1TausPset, {l1TausPSetDefault});
265  desc.add<edm::InputTag>("hbheInput", edm::InputTag("hltHbhereco"))->setComment("HBHE recHit collection");
266  desc.add<edm::InputTag>("hoInput", edm::InputTag("hltHoreco"))->setComment("HO recHit Collection");
267  desc.add<edm::InputTag>("ebInput", edm::InputTag("hltEcalRecHit:EcalRecHitsEB"))->setComment("EB recHit Collection");
268  desc.add<edm::InputTag>("eeInput", edm::InputTag("hltEcalRecHit:EcalRecHitsEE"))->setComment("EE recHit Collection");
269  desc.add<edm::InputTag>("pataVertices", edm::InputTag("hltPixelVerticesSoA"))
270  ->setComment("patatrack vertices collection");
271  desc.add<edm::InputTag>("pataTracks", edm::InputTag("hltPixelTracksSoA"))->setComment("patatrack collection");
272  desc.add<edm::InputTag>("BeamSpot", edm::InputTag("hltOnlineBeamSpot"))->setComment("BeamSpot Collection");
273  desc.add<uint>("maxVtx", 100)->setComment("max output collection size (number of accepted vertices)");
274  desc.add<double>("fractionSumPt2", 0.3)->setComment("threshold on sumPt2 fraction of the leading vertex");
275  desc.add<double>("minSumPt2", 0.)->setComment("min sumPt2");
276  desc.add<double>("track_pt_min", 1.0)->setComment("min track p_T");
277  desc.add<double>("track_pt_max", 10.0)->setComment("max track p_T");
278  desc.add<double>("track_chi2_max", 99999.)->setComment("max track chi2");
279  desc.add<std::string>("graphPath", "RecoTauTag/TrainingFiles/data/L2TauNNTag/L2TauTag_Run3v1.pb")
280  ->setComment("path to the saved CNN");
281  desc.add<std::string>("normalizationDict", "RecoTauTag/TrainingFiles/data/L2TauNNTag/NormalizationDict.json")
282  ->setComment("path to the dictionary for variable standardization");
283  descriptions.addWithDefaultLabel(desc);
284 }
void setComment(std::string const &value)
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:135
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void L2TauNNProducer::fillL1TauVars ( tensorflow::Tensor &  cellGridMatrix,
const std::vector< l1t::TauRef > &  allTaus 
)
private

Definition at line 400 of file L2TauTagNNProducer.cc.

References input, L2TauTagNNv1::nCellEta, and L2TauTagNNv1::nCellPhi.

Referenced by produce().

400  {
402  const int nTaus = static_cast<int>(allTaus.size());
403  for (int tau_idx = 0; tau_idx < nTaus; tau_idx++) {
404  for (int eta_idx = 0; eta_idx < L2TauTagNNv1::nCellEta; eta_idx++) {
405  for (int phi_idx = 0; phi_idx < L2TauTagNNv1::nCellPhi; phi_idx++) {
406  auto getCell = [&](NNInputs input) -> float& {
407  return getCellImpl(cellGridMatrix, tau_idx, phi_idx, eta_idx, input);
408  };
409  getCell(NNInputs::l1Tau_pt) = allTaus[tau_idx]->pt();
410  getCell(NNInputs::l1Tau_eta) = allTaus[tau_idx]->eta();
411  getCell(NNInputs::l1Tau_hwIso) = allTaus[tau_idx]->hwIso();
412  }
413  }
414  }
415 }
static std::string const input
Definition: EdmProvDump.cc:47
constexpr int nCellEta
constexpr int nCellPhi
void L2TauNNProducer::fillPatatracks ( tensorflow::Tensor &  cellGridMatrix,
const std::vector< l1t::TauRef > &  allTaus,
const pixelTrack::TrackSoA patatracks_tsoa,
const ZVertexSoA patavtx_soa,
const reco::BeamSpot beamspot,
const MagneticField magfi 
)
private

Definition at line 666 of file L2TauTagNNProducer.cc.

References TrackSoAHeterogeneousT< S >::charge(), TrackSoAHeterogeneousT< S >::chi2, reco::deltaR2(), dR2_max, TrackSoAHeterogeneousT< S >::eta, spr::find(), getEtaPhiIndices(), ZVertexSoA::idv, impactParameter(), PyquenDefaultSettings_cff::impactParameters, input, pixelTrack::loose, HLT_FULL_cff::maxTracks, L2TauTagNNv1::nCellEta, L2TauTagNNv1::nCellPhi, TrackSoAHeterogeneousT< S >::nHits(), nHits, HLT_FULL_cff::nVertices, TrackSoAHeterogeneousT< S >::phi(), TrackSoAHeterogeneousT< S >::pt, submitPVResolutionJobs::q, quality, TrackSoAHeterogeneousT< S >::qualityData(), selectGoodVertices(), and TrackSoAHeterogeneousT< S >::stride().

Referenced by produce().

671  {
673  float deta, dphi;
674  int eta_idx = 0;
675  int phi_idx = 0;
676  int tau_idx = 0;
677 
678  auto getCell = [&](NNInputs input) -> float& {
679  return getCellImpl(cellGridMatrix, tau_idx, phi_idx, eta_idx, input);
680  };
681  const int nTaus = static_cast<int>(allTaus.size());
682  for (tau_idx = 0; tau_idx < nTaus; tau_idx++) {
683  const float tauEta = allTaus[tau_idx]->eta();
684  const float tauPhi = allTaus[tau_idx]->phi();
685 
686  auto maxTracks = patatracks_tsoa.stride();
687  auto const* quality = patatracks_tsoa.qualityData();
688 
689  std::vector<int> TrackGood;
690  for (int32_t it = 0; it < maxTracks; ++it) {
691  auto nHits = patatracks_tsoa.nHits(it);
692  if (nHits == 0)
693  break;
694  auto q = quality[it];
696  continue;
697  if (nHits < 0)
698  continue;
699  TrackGood.push_back(it);
700  }
701 
702  std::vector<int> VtxGood = selectGoodVertices(patavtx_soa, patatracks_tsoa, TrackGood);
703 
704  for (const auto it : TrackGood) {
705  const float patatrackPt = patatracks_tsoa.pt[it];
706  if (patatrackPt <= 0)
707  continue;
708  const float patatrackPhi = patatracks_tsoa.phi(it);
709  const float patatrackEta = patatracks_tsoa.eta(it);
710  const float patatrackCharge = patatracks_tsoa.charge(it);
711  const float patatrackChi2OverNdof = patatracks_tsoa.chi2(it);
712  const auto nHits = patatracks_tsoa.nHits(it);
713  if (nHits <= 0)
714  continue;
715  const int patatrackNdof = 2 * nHits - 5;
716 
717  const int vtx_idx_assTrk = patavtx_soa.idv[it];
718  if (reco::deltaR2(patatrackEta, patatrackPhi, tauEta, tauPhi) < dR2_max) {
719  std::tie(deta, dphi, eta_idx, phi_idx) =
720  getEtaPhiIndices(patatrackEta, patatrackPhi, allTaus[tau_idx]->polarP4());
721  getCell(NNInputs::PatatrackPtSum) += patatrackPt;
722  getCell(NNInputs::PatatrackSize) += 1.;
723  getCell(NNInputs::PatatrackChargeSum) += patatrackCharge;
724  getCell(NNInputs::PatatrackDeltaEta) += deta * patatrackPt;
725  getCell(NNInputs::PatatrackDeltaPhi) += dphi * patatrackPt;
726  getCell(NNInputs::PatatrackChi2OverNdof) += patatrackChi2OverNdof * patatrackPt;
727  getCell(NNInputs::PatatrackNdof) += patatrackNdof * patatrackPt;
728  std::pair<float, float> impactParameters = impactParameter(it, patatracks_tsoa, patatrackPhi, beamspot, magfi);
729  getCell(NNInputs::PatatrackDxy) += impactParameters.first * patatrackPt;
730  getCell(NNInputs::PatatrackDz) += impactParameters.second * patatrackPt;
731  if ((std::find(VtxGood.begin(), VtxGood.end(), vtx_idx_assTrk) != VtxGood.end())) {
732  getCell(NNInputs::PatatrackPtSumWithVertex) += patatrackPt;
733  getCell(NNInputs::PatatrackSizeWithVertex) += 1.;
734  }
735  }
736  }
737 
738  // normalize to sum and define stdDev
739  for (eta_idx = 0; eta_idx < L2TauTagNNv1::nCellEta; eta_idx++) {
740  for (phi_idx = 0; phi_idx < L2TauTagNNv1::nCellPhi; phi_idx++) {
741  getCell(NNInputs::nVertices) = VtxGood.size();
742  if (getCell(NNInputs::PatatrackPtSum) > 0.) {
743  getCell(NNInputs::PatatrackDeltaEta) /= getCell(NNInputs::PatatrackPtSum);
744  getCell(NNInputs::PatatrackDeltaPhi) /= getCell(NNInputs::PatatrackPtSum);
745  getCell(NNInputs::PatatrackChi2OverNdof) /= getCell(NNInputs::PatatrackPtSum);
746  getCell(NNInputs::PatatrackNdof) /= getCell(NNInputs::PatatrackPtSum);
747  getCell(NNInputs::PatatrackDxy) /= getCell(NNInputs::PatatrackPtSum);
748  getCell(NNInputs::PatatrackDz) /= getCell(NNInputs::PatatrackPtSum);
749  }
750  }
751  }
752  }
753 }
uint32_t const *__restrict__ Quality * quality
static constexpr int32_t stride()
constexpr Quality const * qualityData() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
std::tuple< float, float, int, int > getEtaPhiIndices(const VPos &position, const LVec &tau_p4)
std::vector< int > selectGoodVertices(const ZVertexSoA &patavtx_soa, const pixelTrack::TrackSoA &patatracks_tsoa, const std::vector< int > &TrackGood)
std::pair< float, float > impactParameter(int it, const pixelTrack::TrackSoA &patatracks_tsoa, float patatrackPhi, const reco::BeamSpot &beamspot, const MagneticField *magfi)
constexpr float charge(int32_t i) const
static std::string const input
Definition: EdmProvDump.cc:47
eigenSoA::ScalarSoA< float, S > pt
eigenSoA::ScalarSoA< float, S > chi2
constexpr int nHits(int i) const
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
caConstants::TupleMultiplicity const CAHitNtupletGeneratorKernelsGPU::HitToTuple const cms::cuda::AtomicPairCounter GPUCACell const *__restrict__ uint32_t const *__restrict__ gpuPixelDoublets::CellNeighborsVector const gpuPixelDoublets::CellTracksVector const GPUCACell::OuterHitOfCell const int32_t nHits
constexpr float phi(int32_t i) const
int16_t idv[MAXTRACKS]
Definition: ZVertexSoA.h:14
static constexpr float dR2_max
constexpr int nCellEta
eigenSoA::ScalarSoA< float, S > eta
constexpr int nCellPhi
template<typename VPos , typename LVec >
std::tuple< float, float, int, int > L2TauNNProducer::getEtaPhiIndices ( const VPos &  position,
const LVec &  tau_p4 
)
private

Definition at line 427 of file L2TauTagNNProducer.cc.

Referenced by fillCaloRecHits(), and fillPatatracks().

427  {
428  return getEtaPhiIndices(position.eta(), position.phi(), tau_p4);
429 }
std::tuple< float, float, int, int > getEtaPhiIndices(const VPos &position, const LVec &tau_p4)
static int position[264][3]
Definition: ReadPGInfo.cc:289
template<typename LVec >
std::tuple< float, float, int, int > L2TauNNProducer::getEtaPhiIndices ( float  eta,
float  phi,
const LVec &  tau_p4 
)
private

Definition at line 418 of file L2TauTagNNProducer.cc.

References reco::deltaPhi(), dEta_width, dPhi_width, and L2TauTagNNv1::dR_max.

418  {
419  const float deta = eta - tau_p4.eta();
420  const float dphi = reco::deltaPhi(phi, tau_p4.phi());
421  const int eta_idx = static_cast<int>(floor((deta + L2TauTagNNv1::dR_max) / dEta_width));
422  const int phi_idx = static_cast<int>(floor((dphi + L2TauTagNNv1::dR_max) / dPhi_width));
423  return std::make_tuple(deta, dphi, eta_idx, phi_idx);
424 }
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
constexpr float dR_max
static constexpr float dPhi_width
static constexpr float dEta_width
std::vector< float > L2TauNNProducer::getTauScore ( const tensorflow::Tensor &  cellGridMatrix)
private

Definition at line 755 of file L2TauTagNNProducer.cc.

References inputTensorName_, L2cacheData_, tensorflow::run(), and L2TauNNProducerCacheData::session.

Referenced by produce().

755  {
756  std::vector<tensorflow::Tensor> pred_tensor;
757  tensorflow::run(L2cacheData_->session, {{inputTensorName_, cellGridMatrix}}, {outputTensorName_}, &pred_tensor);
758  const int nTau = cellGridMatrix.shape().dim_size(0);
759  std::vector<float> pred_vector(nTau);
760  for (int tau_idx = 0; tau_idx < nTau; ++tau_idx) {
761  pred_vector[tau_idx] = pred_tensor[0].matrix<float>()(tau_idx, 0);
762  }
763 
764  return pred_vector;
765 }
std::string inputTensorName_
void run(Session *session, const NamedTensorList &inputs, const std::vector< std::string > &outputNames, std::vector< Tensor > *outputs, const thread::ThreadPoolOptions &threadPoolOptions)
Definition: TensorFlow.cc:213
std::string outputTensorName_
const L2TauNNProducerCacheData * L2cacheData_
tensorflow::Session * session
void L2TauNNProducer::globalEndJob ( L2TauNNProducerCacheData cacheData)
static

Definition at line 248 of file L2TauTagNNProducer.cc.

References tensorflow::closeSession(), L2TauNNProducerCacheData::graphDef, and L2TauNNProducerCacheData::session.

248  {
249  if (cacheData->graphDef != nullptr) {
250  delete cacheData->graphDef;
251  }
252  tensorflow::closeSession(cacheData->session);
253 }
bool closeSession(Session *&session)
Definition: TensorFlow.cc:198
tensorflow::GraphDef * graphDef
tensorflow::Session * session
std::pair< float, float > L2TauNNProducer::impactParameter ( int  it,
const pixelTrack::TrackSoA patatracks_tsoa,
float  patatrackPhi,
const reco::BeamSpot beamspot,
const MagneticField magfi 
)
private

Definition at line 634 of file L2TauTagNNProducer.cc.

References LocalTrajectoryParameters::charge(), funct::cos(), CommonMethods::cp(), validate-o2o-wbm::f, gpuVertexFinder::fit, runTauDisplay::gp, M_PI_2, LocalTrajectoryParameters::momentum(), phi, LocalTrajectoryParameters::position(), createTree::pp, funct::sin(), TrackSoAHeterogeneousT< S >::stateAtBS, riemannFit::transformToPerigeePlane(), reco::BeamSpot::x0(), reco::BeamSpot::y0(), and reco::BeamSpot::z0().

Referenced by fillPatatracks().

638  {
639  auto const& fit = patatracks_tsoa.stateAtBS;
640  /* dxy and dz */
641  riemannFit::Vector5d ipar, opar;
642  riemannFit::Matrix5d icov, ocov;
643  fit.copyToDense(ipar, icov, it);
644  riemannFit::transformToPerigeePlane(ipar, icov, opar, ocov);
645  LocalTrajectoryParameters lpar(opar(0), opar(1), opar(2), opar(3), opar(4), 1.);
646  float sp = std::sin(patatrackPhi);
647  float cp = std::cos(patatrackPhi);
648  Surface::RotationType Rotation(sp, -cp, 0, 0, 0, -1.f, cp, sp, 0);
649  GlobalPoint BeamSpotPoint(beamspot.x0(), beamspot.y0(), beamspot.z0());
650  Plane impPointPlane(BeamSpotPoint, Rotation);
652  impPointPlane.toGlobal(lpar.position()), impPointPlane.toGlobal(lpar.momentum()), lpar.charge(), magfi);
653  GlobalPoint vv = gp.position();
654  math::XYZPoint pos(vv.x(), vv.y(), vv.z());
655  GlobalVector pp = gp.momentum();
656  math::XYZVector mom(pp.x(), pp.y(), pp.z());
657  auto lambda = M_PI_2 - pp.theta();
658  auto phi = pp.phi();
659  float patatrackDxy = -vv.x() * std::sin(phi) + vv.y() * std::cos(phi);
660  float patatrackDz =
661  (vv.z() * std::cos(lambda) - (vv.x() * std::cos(phi) + vv.y() * std::sin(phi)) * std::sin(lambda)) /
662  std::cos(lambda);
663  return std::make_pair(patatrackDxy, patatrackDz);
664 }
double z0() const
z coordinate
Definition: BeamSpot.h:65
tuple pp
Definition: createTree.py:17
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
#define M_PI_2
Definition: Plane.h:16
Eigen::Matrix< double, 5, 1 > Vector5d
Definition: FitResult.h:16
__host__ __device__ void transformToPerigeePlane(VI5 const &ip, MI5 const &icov, VO5 &op, MO5 &ocov)
Definition: FitUtils.h:218
auto const & fit
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
TrajectoryStateSoAT< S > stateAtBS
SOARotation< float > Rotation
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
Eigen::Matrix< double, 5, 5 > Matrix5d
Definition: FitResult.h:20
double y0() const
y coordinate
Definition: BeamSpot.h:63
double x0() const
x coordinate
Definition: BeamSpot.h:61
std::unique_ptr< L2TauNNProducerCacheData > L2TauNNProducer::initializeGlobalCache ( const edm::ParameterSet cfg)
static

Definition at line 223 of file L2TauTagNNProducer.cc.

References tensorflow::createSession(), edm::FileInPath::fullPath(), edm::ParameterSet::getParameter(), submitPVResolutionJobs::key, tensorflow::loadGraphDef(), normDictElement::max, normDictElement::mean, normDictElement::min, L2TauTagNNv1::nVars, tensorflow::setLogging(), normDictElement::std, AlCaHLTBitMon_QueryRunRegistry::string, hgcalPerformanceValidation::val, isotrackApplyRegressor::var, and L2TauTagNNv1::varNameMap.

223  {
224  std::unique_ptr<L2TauNNProducerCacheData> cacheData = std::make_unique<L2TauNNProducerCacheData>();
225  cacheData->normVec.reserve(L2TauTagNNv1::nVars);
226 
227  auto const graphPath = edm::FileInPath(cfg.getParameter<std::string>("graphPath")).fullPath();
228 
229  cacheData->graphDef = tensorflow::loadGraphDef(graphPath);
230  cacheData->session = tensorflow::createSession(cacheData->graphDef);
231 
233 
234  boost::property_tree::ptree loadPtreeRoot;
235  auto const normalizationDict = edm::FileInPath(cfg.getParameter<std::string>("normalizationDict")).fullPath();
236  boost::property_tree::read_json(normalizationDict, loadPtreeRoot);
237  for (const auto& [key, val] : L2TauTagNNv1::varNameMap) {
238  boost::property_tree::ptree var = loadPtreeRoot.get_child(val);
239  normDictElement current_element;
240  current_element.mean = var.get_child("mean").get_value<float>();
241  current_element.std = var.get_child("std").get_value<float>();
242  current_element.min = var.get_child("min").get_value<float>();
243  current_element.max = var.get_child("max").get_value<float>();
244  cacheData->normVec.push_back(current_element);
245  }
246  return cacheData;
247 }
Session * createSession(SessionOptions &sessionOptions)
Definition: TensorFlow.cc:85
GraphDef * loadGraphDef(const std::string &pbFile)
Definition: TensorFlow.cc:68
constexpr int nVars
const std::map< NNInputs, std::string > varNameMap
list var
if using global norm cols_to_minmax = [&#39;t_delta&#39;, &#39;t_hmaxNearP&#39;,&#39;t_emaxNearP&#39;, &#39;t_hAnnular&#39;, &#39;t_eAnnular&#39;,&#39;t_pt&#39;,&#39;t_nVtx&#39;,&#39;t_ieta&#39;,&#39;t_eHcal10&#39;, &#39;t_eHcal30&#39;,&#39;t_rhoh&#39;,&#39;t_eHcal&#39;] df[cols_to_minmax] = df[cols_to_minmax].apply(lambda x: (x - x.min()) / (x.max() - x.min()) if (x.max() - x.min() &gt; 0) else 1.0/200.0)
tuple key
prepare the HTCondor submission files and eventually submit them
void setLogging(const std::string &level="3")
Definition: TensorFlow.cc:15
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::string fullPath() const
Definition: FileInPath.cc:161
void L2TauNNProducer::produce ( edm::Event event,
const edm::EventSetup eventsetup 
)
overrideprivate

Definition at line 767 of file L2TauTagNNProducer.cc.

References beamSpotToken_, bFieldToken_, checknan(), debugLevel_, HLT_FULL_cff::distance, L2TauNNProducer::caloRecHitCollections::eb, ebToken_, L2TauNNProducer::caloRecHitCollections::ee, eeToken_, fillCaloRecHits(), fillL1TauVars(), fillPatatracks(), spr::find(), relativeConstraints::geometry, L2TauNNProducer::caloRecHitCollections::geometry, geometryToken_, edm::EventSetup::getHandle(), getTauScore(), L2TauNNProducer::caloRecHitCollections::hbhe, hbheToken_, hcalSimParameters_cfi::ho, L2TauNNProducer::caloRecHitCollections::ho, hoToken_, L1TauDesc_, eostools::move(), L2TauTagNNv1::nCellEta, L2TauTagNNv1::nCellPhi, L2TauTagNNv1::nVars, pataTracksToken_, pataVerticesToken_, DiDispStaMuonMonitor_cfi::pt, standardizeTensor(), and trigger::TriggerL1Tau.

767  {
768  std::vector<std::vector<size_t>> TauCollectionMap(L1TauDesc_.size());
769  l1t::TauVectorRef allTaus;
770 
771  for (size_t inp_idx = 0; inp_idx < L1TauDesc_.size(); inp_idx++) {
772  l1t::TauVectorRef l1Taus;
773  auto const& l1TriggeredTaus = event.get(L1TauDesc_[inp_idx].inputToken_);
774  l1TriggeredTaus.getObjects(trigger::TriggerL1Tau, l1Taus);
775  TauCollectionMap.at(inp_idx).resize(l1Taus.size());
776 
777  for (size_t l1_idx = 0; l1_idx < l1Taus.size(); l1_idx++) {
778  size_t tau_idx;
779  const auto iter = std::find(allTaus.begin(), allTaus.end(), l1Taus[l1_idx]);
780  if (iter != allTaus.end()) {
781  tau_idx = std::distance(allTaus.begin(), iter);
782  } else {
783  allTaus.push_back(l1Taus[l1_idx]);
784  tau_idx = allTaus.size() - 1;
785  }
786  TauCollectionMap.at(inp_idx).at(l1_idx) = tau_idx;
787  }
788  }
789  const auto ebCal = event.getHandle(ebToken_);
790  const auto eeCal = event.getHandle(eeToken_);
791  const auto hbhe = event.getHandle(hbheToken_);
792  const auto ho = event.getHandle(hoToken_);
793  const auto& patatracks_SoA = *event.get(pataTracksToken_);
794  const auto& vertices_SoA = *event.get(pataVerticesToken_);
795  const auto bsHandle = event.getHandle(beamSpotToken_);
796 
797  auto const fieldESH = eventsetup.getHandle(bFieldToken_);
798  auto const geometry = eventsetup.getHandle(geometryToken_);
799 
800  caloRecHitCollections caloRecHits;
801  caloRecHits.hbhe = &*hbhe;
802  caloRecHits.ho = &*ho;
803  caloRecHits.eb = &*ebCal;
804  caloRecHits.ee = &*eeCal;
805  caloRecHits.geometry = &*geometry;
806 
807  const int nTaus = static_cast<int>(allTaus.size());
808  tensorflow::Tensor cellGridMatrix(tensorflow::DT_FLOAT,
810  const int n_inputs = nTaus * L2TauTagNNv1::nCellEta * L2TauTagNNv1::nCellPhi * L2TauTagNNv1::nVars;
811  for (int input_idx = 0; input_idx < n_inputs; ++input_idx) {
812  cellGridMatrix.flat<float>()(input_idx) = 0;
813  }
814  fillL1TauVars(cellGridMatrix, allTaus);
815 
816  fillCaloRecHits(cellGridMatrix, allTaus, caloRecHits);
817 
818  fillPatatracks(cellGridMatrix, allTaus, patatracks_SoA, vertices_SoA, *bsHandle, fieldESH.product());
819 
820  standardizeTensor(cellGridMatrix);
821 
822  if (debugLevel_ > 0) {
823  checknan(cellGridMatrix, debugLevel_);
824  }
825 
826  std::vector<float> tau_score = getTauScore(cellGridMatrix);
827 
828  for (size_t inp_idx = 0; inp_idx < L1TauDesc_.size(); inp_idx++) {
829  const size_t nTau = TauCollectionMap[inp_idx].size();
830  auto tau_tags = std::make_unique<std::vector<float>>(nTau);
831  for (size_t tau_pos = 0; tau_pos < nTau; ++tau_pos) {
832  const auto tau_idx = TauCollectionMap[inp_idx][tau_pos];
833  if (debugLevel_ > 0) {
834  edm::LogInfo("DebugInfo") << event.id().event() << " \t " << (allTaus[tau_idx])->pt() << " \t "
835  << tau_score.at(tau_idx) << std::endl;
836  }
837  (*tau_tags)[tau_pos] = tau_score.at(tau_idx);
838  }
839  event.put(std::move(tau_tags), L1TauDesc_[inp_idx].CollectionName);
840  }
841 }
const edm::EDGetTokenT< PixelTrackHeterogeneous > pataTracksToken_
void standardizeTensor(tensorflow::Tensor &tensor)
const edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
std::vector< float > getTauScore(const tensorflow::Tensor &cellGridMatrix)
const edm::EDGetTokenT< HORecHitCollection > hoToken_
std::vector< InputDescTau > L1TauDesc_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
void checknan(tensorflow::Tensor &tensor, int debugLevel)
void fillCaloRecHits(tensorflow::Tensor &cellGridMatrix, const std::vector< l1t::TauRef > &allTaus, const caloRecHitCollections &caloRecHits)
constexpr int nVars
const edm::EDGetTokenT< ZVertexHeterogeneous > pataVerticesToken_
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > bFieldToken_
def move
Definition: eostools.py:511
std::vector< TauRef > TauVectorRef
Definition: Tau.h:14
const edm::EDGetTokenT< HBHERecHitCollection > hbheToken_
void fillL1TauVars(tensorflow::Tensor &cellGridMatrix, const std::vector< l1t::TauRef > &allTaus)
Log< level::Info, false > LogInfo
constexpr int nCellEta
const edm::EDGetTokenT< EcalRecHitCollection > eeToken_
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:157
const edm::EDGetTokenT< EcalRecHitCollection > ebToken_
void fillPatatracks(tensorflow::Tensor &cellGridMatrix, const std::vector< l1t::TauRef > &allTaus, const pixelTrack::TrackSoA &patatracks_tsoa, const ZVertexSoA &patavtx_soa, const reco::BeamSpot &beamspot, const MagneticField *magfi)
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > geometryToken_
constexpr int nCellPhi
std::vector< int > L2TauNNProducer::selectGoodVertices ( const ZVertexSoA patavtx_soa,
const pixelTrack::TrackSoA patatracks_tsoa,
const std::vector< int > &  TrackGood 
)
private

Definition at line 569 of file L2TauTagNNProducer.cc.

References cms::cuda::assert(), TrackSoAHeterogeneousT< S >::chi2, fractionSumPt2_, ZVertexSoA::idv, dqmiolumiharvest::j, HLT_FULL_cff::maxTracks, maxVtx_, minSumPt2_, nt, ZVertexSoA::nvFinal, TrackSoAHeterogeneousT< S >::pt, ZVertexSoA::sortInd, TrackSoAHeterogeneousT< S >::stride(), trackChi2Max_, trackPtMax_, and trackPtMin_.

Referenced by fillPatatracks().

571  {
572  auto maxTracks = patatracks_tsoa.stride();
573  const int nv = patavtx_soa.nvFinal;
574  std::vector<int> VtxGood;
575  if (nv == 0)
576  return VtxGood;
577  VtxGood.reserve(nv);
578 
579  std::vector<double> maxChi2_;
580  std::vector<double> pTSquaredSum(nv);
581 
582  for (int j = nv - 1; j >= 0; --j) {
583  std::vector<int> trk_ass_to_vtx;
584  auto vtx_idx = patavtx_soa.sortInd[j];
585  assert(vtx_idx < nv);
586  for (int trk_idx = 0; trk_idx < maxTracks; trk_idx++) {
587  int vtx_ass_to_track = patavtx_soa.idv[trk_idx];
588  if (vtx_ass_to_track == int16_t(vtx_idx))
589  trk_ass_to_vtx.push_back(trk_idx);
590  }
591  auto nt = trk_ass_to_vtx.size();
592  if (nt == 0) {
593  continue;
594  }
595  if (nt < 2) {
596  trk_ass_to_vtx.clear();
597  continue;
598  }
599  for (const auto& trk_idx : trk_ass_to_vtx) {
600  int vtx_ass_to_track = patavtx_soa.idv[trk_idx];
601  if (vtx_ass_to_track != vtx_idx)
602  continue;
603  double patatrackPt = patatracks_tsoa.pt[trk_idx];
604  if (patatrackPt < trackPtMin_)
605  continue;
606  if (patatracks_tsoa.chi2(trk_idx) > trackChi2Max_)
607  continue;
608  if (patatrackPt > trackPtMax_) {
609  patatrackPt = trackPtMax_;
610  }
611  pTSquaredSum.at(vtx_idx) += patatrackPt * patatrackPt;
612  }
613  }
614  std::vector<size_t> sortIdxs(nv);
615  std::iota(sortIdxs.begin(), sortIdxs.end(), 0);
616  std::sort(sortIdxs.begin(), sortIdxs.end(), [&](size_t const i1, size_t const i2) {
617  return pTSquaredSum[i1] > pTSquaredSum[i2];
618  });
619  auto const minFOM_fromFrac = pTSquaredSum[sortIdxs.front()] * fractionSumPt2_;
620 
621  for (int j = nv - 1; j >= 0; --j) {
622  auto idx = patavtx_soa.sortInd[j];
623 
624  if (VtxGood.size() >= maxVtx_) {
625  break;
626  }
627  if (pTSquaredSum[idx] >= minFOM_fromFrac && pTSquaredSum[idx] > minSumPt2_) {
628  VtxGood.push_back(idx);
629  }
630  }
631  return VtxGood;
632 }
static constexpr int32_t stride()
const unsigned int maxVtx_
assert(be >=bs)
eigenSoA::ScalarSoA< float, S > pt
eigenSoA::ScalarSoA< float, S > chi2
const double minSumPt2_
const double trackPtMax_
const double trackChi2Max_
int nt
Definition: AMPTWrapper.h:42
const double trackPtMin_
const double fractionSumPt2_
int16_t idv[MAXTRACKS]
Definition: ZVertexSoA.h:14
uint32_t nvFinal
Definition: ZVertexSoA.h:21
uint16_t sortInd[MAXVTX]
Definition: ZVertexSoA.h:20
void L2TauNNProducer::standardizeTensor ( tensorflow::Tensor &  tensor)
private

Definition at line 366 of file L2TauTagNNProducer.cc.

References ztail::d, Exception, input, L2cacheData_, SiStripPI::max, SiStripPI::mean, min(), and L2TauNNProducerCacheData::normVec.

Referenced by produce().

366  {
368  std::vector<int> tensor_shape(tensor.shape().dims());
369  for (int d = 0; d < tensor.shape().dims(); d++) {
370  tensor_shape.at(d) = tensor.shape().dim_size(d);
371  }
372  if (tensor_shape.size() != 4) {
373  throw cms::Exception("InvalidTensor") << "Tensor shape does not have 4 dimensions!";
374  }
375  for (int tau_idx = 0; tau_idx < tensor_shape.at(0); tau_idx++) {
376  for (int phi_idx = 0; phi_idx < tensor_shape.at(1); phi_idx++) {
377  for (int eta_idx = 0; eta_idx < tensor_shape.at(2); eta_idx++) {
378  for (int var_idx = 0; var_idx < tensor_shape.at(3); var_idx++) {
379  auto getCell = [&](NNInputs input) -> float& {
380  return getCellImpl(tensor, tau_idx, phi_idx, eta_idx, input);
381  };
382  float mean = L2cacheData_->normVec.at(var_idx).mean;
383  float std = L2cacheData_->normVec.at(var_idx).std;
384  float min = L2cacheData_->normVec.at(var_idx).min;
385  float max = L2cacheData_->normVec.at(var_idx).max;
386  float nonstd_var = getCell(static_cast<NNInputs>(var_idx));
387  float std_var = static_cast<float>((nonstd_var - mean) / std);
388  if (std_var > max) {
389  std_var = static_cast<float>(max);
390  } else if (std_var < min) {
391  std_var = static_cast<float>(min);
392  }
393  getCell(static_cast<NNInputs>(var_idx)) = std_var;
394  }
395  }
396  }
397  }
398 }
static std::string const input
Definition: EdmProvDump.cc:47
tuple d
Definition: ztail.py:151
std::vector< normDictElement > normVec
T min(T a, T b)
Definition: MathUtil.h:58
const L2TauNNProducerCacheData * L2cacheData_

Member Data Documentation

const edm::EDGetTokenT<reco::BeamSpot> L2TauNNProducer::beamSpotToken_
private

Definition at line 211 of file L2TauTagNNProducer.cc.

Referenced by produce().

const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> L2TauNNProducer::bFieldToken_
private

Definition at line 208 of file L2TauTagNNProducer.cc.

Referenced by produce().

const int L2TauNNProducer::debugLevel_
private

Definition at line 200 of file L2TauTagNNProducer.cc.

Referenced by produce().

constexpr float L2TauNNProducer::dEta_width = 2 * L2TauTagNNv1::dR_max / static_cast<float>(L2TauTagNNv1::nCellEta)
static

Definition at line 163 of file L2TauTagNNProducer.cc.

Referenced by getEtaPhiIndices().

constexpr float L2TauNNProducer::dPhi_width = 2 * L2TauTagNNv1::dR_max / static_cast<float>(L2TauTagNNv1::nCellPhi)
static

Definition at line 164 of file L2TauTagNNProducer.cc.

Referenced by getEtaPhiIndices().

constexpr float L2TauNNProducer::dR2_max = L2TauTagNNv1::dR_max * L2TauTagNNv1::dR_max
static

Definition at line 162 of file L2TauTagNNProducer.cc.

Referenced by fillCaloRecHits(), and fillPatatracks().

const edm::EDGetTokenT<EcalRecHitCollection> L2TauNNProducer::ebToken_
private

Definition at line 205 of file L2TauTagNNProducer.cc.

Referenced by produce().

const edm::EDGetTokenT<EcalRecHitCollection> L2TauNNProducer::eeToken_
private

Definition at line 206 of file L2TauTagNNProducer.cc.

Referenced by produce().

const double L2TauNNProducer::fractionSumPt2_
private

Definition at line 213 of file L2TauTagNNProducer.cc.

Referenced by selectGoodVertices().

const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> L2TauNNProducer::geometryToken_
private

Definition at line 207 of file L2TauTagNNProducer.cc.

Referenced by produce().

const edm::EDGetTokenT<HBHERecHitCollection> L2TauNNProducer::hbheToken_
private

Definition at line 203 of file L2TauTagNNProducer.cc.

Referenced by produce().

const edm::EDGetTokenT<HORecHitCollection> L2TauNNProducer::hoToken_
private

Definition at line 204 of file L2TauTagNNProducer.cc.

Referenced by produce().

std::string L2TauNNProducer::inputTensorName_
private

Definition at line 218 of file L2TauTagNNProducer.cc.

Referenced by getTauScore(), and L2TauNNProducer().

std::vector<InputDescTau> L2TauNNProducer::L1TauDesc_
private

Definition at line 202 of file L2TauTagNNProducer.cc.

Referenced by L2TauNNProducer(), and produce().

const L2TauNNProducerCacheData* L2TauNNProducer::L2cacheData_
private

Definition at line 220 of file L2TauTagNNProducer.cc.

Referenced by getTauScore(), L2TauNNProducer(), and standardizeTensor().

const unsigned int L2TauNNProducer::maxVtx_
private

Definition at line 212 of file L2TauTagNNProducer.cc.

Referenced by selectGoodVertices().

const double L2TauNNProducer::minSumPt2_
private

Definition at line 214 of file L2TauTagNNProducer.cc.

Referenced by selectGoodVertices().

std::string L2TauNNProducer::outputTensorName_
private

Definition at line 219 of file L2TauTagNNProducer.cc.

Referenced by L2TauNNProducer().

const edm::EDGetTokenT<PixelTrackHeterogeneous> L2TauNNProducer::pataTracksToken_
private

Definition at line 210 of file L2TauTagNNProducer.cc.

Referenced by produce().

const edm::EDGetTokenT<ZVertexHeterogeneous> L2TauNNProducer::pataVerticesToken_
private

Definition at line 209 of file L2TauTagNNProducer.cc.

Referenced by produce().

const edm::EDGetTokenT<trigger::TriggerFilterObjectWithRefs> L2TauNNProducer::tauTriggerToken_
private

Definition at line 201 of file L2TauTagNNProducer.cc.

const double L2TauNNProducer::trackChi2Max_
private

Definition at line 217 of file L2TauTagNNProducer.cc.

Referenced by selectGoodVertices().

const double L2TauNNProducer::trackPtMax_
private

Definition at line 216 of file L2TauTagNNProducer.cc.

Referenced by selectGoodVertices().

const double L2TauNNProducer::trackPtMin_
private

Definition at line 215 of file L2TauTagNNProducer.cc.

Referenced by selectGoodVertices().