CMS 3D CMS Logo

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

Public Member Functions

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

Static Public Member Functions

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

Private Member Functions

void addTau (const l1t::PFCandidate &iCand, const l1t::PFCandidateCollection &iParts, std::unique_ptr< PFTauCollection > &outputTaus)
 
void produce (edm::Event &iEvent, const edm::EventSetup &iSetup) override
 

Private Attributes

double fConeSize_
 
edm::EDGetTokenT< vector
< l1t::PFCandidate > > 
fL1PFToken_
 
int fMaxTaus_
 
int fNParticles_
 
double fSeedPt_
 
std::unique_ptr< TauNNIdfTauNNId_
 
double fTauSize_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer< edm::GlobalCache< TauNNTFCache > >
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 17 of file L1NNTauProducer.cc.

Constructor & Destructor Documentation

L1NNTauProducer::L1NNTauProducer ( const edm::ParameterSet cfg,
const TauNNTFCache cache 
)
explicit

Definition at line 43 of file L1NNTauProducer.cc.

References utilities::cache(), fNParticles_, fTauNNId_, edm::ParameterSet::getParameter(), and AlCaHLTBitMon_QueryRunRegistry::string.

44  : fSeedPt_(cfg.getParameter<double>("seedpt")),
45  fConeSize_(cfg.getParameter<double>("conesize")),
46  fTauSize_(cfg.getParameter<double>("tausize")),
47  fMaxTaus_(cfg.getParameter<int>("maxtaus")),
48  fNParticles_(cfg.getParameter<int>("nparticles")),
49  fL1PFToken_(consumes<vector<l1t::PFCandidate>>(cfg.getParameter<edm::InputTag>("L1PFObjects"))) {
50  std::string lNNFile = cfg.getParameter<std::string>("NNFileName"); //,"L1Trigger/Phase2L1Taus/data/tau_3layer.pb");
51  fTauNNId_ = std::make_unique<TauNNId>(
52  lNNFile.find("v0") == std::string::npos ? "input_1:0" : "dense_1_input:0", cache, lNNFile, fNParticles_);
53  produces<l1t::PFTauCollection>("L1PFTausNN");
54 }
edm::EDGetTokenT< vector< l1t::PFCandidate > > fL1PFToken_
std::unique_ptr< TauNNId > fTauNNId_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
def cache
Definition: utilities.py:3
L1NNTauProducer::~L1NNTauProducer ( )
override

Definition at line 159 of file L1NNTauProducer.cc.

159 {}

Member Function Documentation

void L1NNTauProducer::addTau ( const l1t::PFCandidate iCand,
const l1t::PFCandidateCollection iParts,
std::unique_ptr< PFTauCollection > &  outputTaus 
)
private

Definition at line 118 of file L1NNTauProducer.cc.

References l1t::PFCandidate::ChargedHadron, reco::deltaR2(), l1t::PFCandidate::Electron, fConeSize_, fSeedPt_, fTauNNId_, fTauSize_, mps_fire::i, dqmiolumiharvest::j, mkfit::NN, l1t::PFCandidate::Photon, and reco::LeafCandidate::pt().

Referenced by produce().

120  {
121  l1t::PFCandidateCollection pfTauCands;
122  math::PtEtaPhiMLorentzVector lTot(0, 0, 0, 0);
123  math::PtEtaPhiMLorentzVector lCand(0, 0, 0, 0);
124  int lId = 0;
125  for (const auto& l1PFCand : iParts) {
126  if (reco::deltaR2(iCand, l1PFCand) > fConeSize_ * fConeSize_)
127  continue;
128  math::PtEtaPhiMLorentzVector pVec(l1PFCand.pt(), l1PFCand.eta(), l1PFCand.phi(), 0);
129  lTot += pVec;
130  if (reco::deltaR2(iCand, l1PFCand) < fTauSize_ * fTauSize_ &&
131  (l1PFCand.id() == l1t::PFCandidate::Electron || l1PFCand.id() == l1t::PFCandidate::ChargedHadron ||
132  l1PFCand.id() == l1t::PFCandidate::Photon)) {
133  lId++;
134  lCand += pVec;
135  }
136  pfTauCands.push_back(l1PFCand);
137  }
138  if (lTot.Pt() < fSeedPt_)
139  return;
140  std::sort(
141  pfTauCands.begin(), pfTauCands.end(), [](l1t::PFCandidate i, l1t::PFCandidate j) { return (i.pt() > j.pt()); });
142  float NN = fTauNNId_->compute(iCand, pfTauCands);
143  math::PtEtaPhiMLorentzVector tempP4(lCand.Pt(), lCand.Eta(), lCand.Phi(), lCand.M());
144  l1t::PFTau l1PFTau(tempP4, NN, 0, lId);
145  outputTaus->push_back(l1PFTau);
146 }
double pt() const final
transverse momentum
std::vector< l1t::PFCandidate > PFCandidateCollection
Definition: PFCandidate.h:57
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
std::unique_ptr< TauNNId > fTauNNId_
constexpr Matriplex::idx_t NN
Definition: Matrix.h:43
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
void L1NNTauProducer::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 147 of file L1NNTauProducer.cc.

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

147  {
148  // L1NNTauProducer
150  desc.add<std::string>("NNFileName", "L1Trigger/Phase2L1ParticleFlow/data/tau_3layer.pb");
151  desc.add<double>("tausize", 0.1);
152  desc.add<int>("maxtaus", 5);
153  desc.add<int>("nparticles", 10);
154  desc.add<double>("conesize", 0.4);
155  desc.add<double>("seedpt", 20);
156  desc.add<edm::InputTag>("L1PFObjects", edm::InputTag("L1PFProducer", "l1pfCandidates"));
157  descriptions.add("L1NNTauProducer", desc);
158 }
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void L1NNTauProducer::globalEndJob ( const TauNNTFCache cache)
static

Definition at line 63 of file L1NNTauProducer.cc.

References TauNNTFCache::graphDef.

63  {
64  if (cache->graphDef != nullptr) {
65  delete cache->graphDef;
66  }
67 }
std::atomic< tensorflow::GraphDef * > graphDef
Definition: TauNNId.h:10
std::unique_ptr< TauNNTFCache > L1NNTauProducer::initializeGlobalCache ( const edm::ParameterSet cfg)
static

Definition at line 55 of file L1NNTauProducer.cc.

References utilities::cache(), personalPlayback::fp, edm::ParameterSet::getParameter(), TauNNTFCache::graphDef, tensorflow::loadGraphDef(), tensorflow::setLogging(), and AlCaHLTBitMon_QueryRunRegistry::string.

55  {
57  std::string lNNFile = cfg.getParameter<std::string>("NNFileName");
58  edm::FileInPath fp(lNNFile);
60  cache->graphDef = tensorflow::loadGraphDef(fp.fullPath());
61  return std::unique_ptr<TauNNTFCache>(cache);
62 }
GraphDef * loadGraphDef(const std::string &pbFile)
Definition: TensorFlow.cc:68
void setLogging(const std::string &level="3")
Definition: TensorFlow.cc:15
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::atomic< tensorflow::GraphDef * > graphDef
Definition: TauNNId.h:10
def cache
Definition: utilities.py:3
void L1NNTauProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 68 of file L1NNTauProducer.cc.

References funct::abs(), addTau(), l1t::PFCandidate::ChargedHadron, reco::deltaR2(), l1t::PFCandidate::Electron, fConeSize_, fL1PFToken_, fMaxTaus_, edm::Event::getByToken(), mps_fire::i, dqmiolumiharvest::j, eostools::move(), reco::LeafCandidate::pt(), edm::Event::put(), and track_trigger_eta_max.

68  {
70  iEvent.getByToken(fL1PFToken_, l1PFCandidates);
71 
72  std::vector<unique_ptr<l1t::PFCandidate>> pfChargedHadrons_sort_v;
73  std::vector<unique_ptr<l1t::PFCandidate>> pfChargedHadrons_seeds_v;
74  for (const auto& l1PFCand : *l1PFCandidates)
75  if ((l1PFCand.id() == l1t::PFCandidate::ChargedHadron || l1PFCand.id() == l1t::PFCandidate::Electron) &&
76  std::abs(l1PFCand.eta()) < track_trigger_eta_max)
77  pfChargedHadrons_sort_v.push_back(std::make_unique<l1t::PFCandidate>(l1PFCand));
78 
79  std::sort(
80  pfChargedHadrons_sort_v.begin(),
81  pfChargedHadrons_sort_v.end(),
82  [](std::unique_ptr<l1t::PFCandidate>& i, std::unique_ptr<l1t::PFCandidate>& j) { return (i->pt() > j->pt()); });
83 
84  auto lTaus = std::make_unique<l1t::PFTauCollection>();
85  if (pfChargedHadrons_sort_v.empty()) {
86  if (lTaus->empty()) {
87  PFTau dummy;
88  lTaus->push_back(dummy);
89  }
90  iEvent.put(std::move(lTaus), "L1PFTausNN");
91  return;
92  }
93  pfChargedHadrons_seeds_v.push_back(std::move(pfChargedHadrons_sort_v[0]));
94  for (unsigned int i0 = 1; i0 < pfChargedHadrons_sort_v.size(); i0++) {
95  bool pMatch = false;
96  for (unsigned int i1 = 0; i1 < pfChargedHadrons_seeds_v.size(); i1++) {
97  if (reco::deltaR2(*(pfChargedHadrons_seeds_v[i1]), *(pfChargedHadrons_sort_v[i0])) < fConeSize_ * fConeSize_)
98  pMatch = true;
99  }
100  if (pMatch)
101  continue;
102  pfChargedHadrons_seeds_v.push_back(std::move(pfChargedHadrons_sort_v[i0]));
103  if (int(pfChargedHadrons_seeds_v.size()) > fMaxTaus_ - 1)
104  break;
105  }
106  for (unsigned int i0 = 0; i0 < pfChargedHadrons_seeds_v.size(); i0++) {
107  addTau(*(pfChargedHadrons_seeds_v[i0]), (*l1PFCandidates), lTaus);
108  }
109  if (lTaus->empty()) {
110  PFTau dummy;
111  lTaus->push_back(dummy);
112  }
113  std::sort(lTaus->begin(), lTaus->end(), [](l1t::PFTau i, l1t::PFTau j) { return (i.pt() > j.pt()); });
114  iEvent.put(std::move(lTaus), "L1PFTausNN");
115 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
static constexpr float track_trigger_eta_max
double pt() const final
transverse momentum
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
edm::EDGetTokenT< vector< l1t::PFCandidate > > fL1PFToken_
void addTau(const l1t::PFCandidate &iCand, const l1t::PFCandidateCollection &iParts, std::unique_ptr< PFTauCollection > &outputTaus)
def move
Definition: eostools.py:511
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16

Member Data Documentation

double L1NNTauProducer::fConeSize_
private

Definition at line 34 of file L1NNTauProducer.cc.

Referenced by addTau(), and produce().

edm::EDGetTokenT<vector<l1t::PFCandidate> > L1NNTauProducer::fL1PFToken_
private

Definition at line 38 of file L1NNTauProducer.cc.

Referenced by produce().

int L1NNTauProducer::fMaxTaus_
private

Definition at line 36 of file L1NNTauProducer.cc.

Referenced by produce().

int L1NNTauProducer::fNParticles_
private

Definition at line 37 of file L1NNTauProducer.cc.

Referenced by L1NNTauProducer().

double L1NNTauProducer::fSeedPt_
private

Definition at line 33 of file L1NNTauProducer.cc.

Referenced by addTau().

std::unique_ptr<TauNNId> L1NNTauProducer::fTauNNId_
private

Definition at line 27 of file L1NNTauProducer.cc.

Referenced by addTau(), and L1NNTauProducer().

double L1NNTauProducer::fTauSize_
private

Definition at line 35 of file L1NNTauProducer.cc.

Referenced by addTau().