CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
TauNNId Class Reference

#include <TauNNId.h>

Public Member Functions

float compute (const l1t::PFCandidate &iSeed, l1t::PFCandidateCollection &iParts)
 
float EvaluateNN ()
 
void setNNVectorVar ()
 
 TauNNId (const std::string &iInput, const TauNNTFCache *cache, const std::string &iWeightFile, int iNParticles)
 
 ~TauNNId ()
 

Private Attributes

unique_ptr< float[]> fEta_
 
unique_ptr< float[]> fId_
 
std::string fInput_
 
int fNParticles_
 
unique_ptr< float[]> fPhi_
 
unique_ptr< float[]> fPt_
 
std::vector< float > NNvectorVar_
 
tensorflow::Session * session_
 

Detailed Description

Definition at line 13 of file TauNNId.h.

Constructor & Destructor Documentation

◆ TauNNId()

TauNNId::TauNNId ( const std::string &  iInput,
const TauNNTFCache cache,
const std::string &  iWeightFile,
int  iNParticles 
)

Definition at line 8 of file TauNNId.cc.

8  {
9  NNvectorVar_.clear();
10  edm::FileInPath fp(iWeightFile);
12  fNParticles_ = iNParticles;
13 
14  fPt_ = std::make_unique<float[]>(fNParticles_);
15  fEta_ = std::make_unique<float[]>(fNParticles_);
16  fPhi_ = std::make_unique<float[]>(fNParticles_);
17  fId_ = std::make_unique<float[]>(fNParticles_);
18  fInput_ = iInput;
19 }

References utilities::cache(), tensorflow::createSession(), fEta_, fId_, fInput_, fNParticles_, personalPlayback::fp, fPhi_, fPt_, NNvectorVar_, and session_.

◆ ~TauNNId()

TauNNId::~TauNNId ( )

Definition at line 21 of file TauNNId.cc.

References tensorflow::closeSession(), and session_.

Member Function Documentation

◆ compute()

float TauNNId::compute ( const l1t::PFCandidate iSeed,
l1t::PFCandidateCollection iParts 
)

Definition at line 51 of file TauNNId.cc.

51  {
52  for (int i0 = 0; i0 < fNParticles_; i0++) {
53  fPt_.get()[i0] = 0;
54  fEta_.get()[i0] = 0;
55  fPhi_.get()[i0] = 0;
56  fId_.get()[i0] = 0;
57  }
58  std::sort(iParts.begin(), iParts.end(), [](l1t::PFCandidate i, l1t::PFCandidate j) { return (i.pt() > j.pt()); });
59  for (unsigned int i0 = 0; i0 < iParts.size(); i0++) {
60  if (i0 > n_particles_max || i0 >= (unsigned int)fNParticles_)
61  break;
62  fPt_.get()[i0] = iParts[i0].pt();
63  fEta_.get()[i0] = iSeed.eta() - iParts[i0].eta();
64  fPhi_.get()[i0] = deltaPhi(iSeed.phi(), iParts[i0].phi());
65  fId_.get()[i0] = iParts[i0].id();
66  }
68  return EvaluateNN();
69 }

References SiPixelRawToDigiRegional_cfi::deltaPhi, reco::LeafCandidate::eta(), EvaluateNN(), fEta_, fId_, fNParticles_, fPhi_, fPt_, mps_fire::i, dqmiolumiharvest::j, n_particles_max, reco::LeafCandidate::phi(), setNNVectorVar(), and jetUpdater_cfi::sort.

◆ EvaluateNN()

float TauNNId::EvaluateNN ( )

Definition at line 40 of file TauNNId.cc.

40  {
41  tensorflow::Tensor input(tensorflow::DT_FLOAT,
42  {1, (unsigned int)NNvectorVar_.size()}); //was {1,35} but get size mismatch, CHECK
43  for (unsigned int i = 0; i < NNvectorVar_.size(); i++) {
44  input.matrix<float>()(0, i) = float(NNvectorVar_[i]);
45  }
46  std::vector<tensorflow::Tensor> outputs;
47  tensorflow::run(session_, {{fInput_, input}}, {"dense_4/Sigmoid:0"}, &outputs);
48  return outputs[0].matrix<float>()(0, 0);
49 } //end EvaluateNN

References fInput_, dqmMemoryStats::float, mps_fire::i, input, createfilelist::int, NNvectorVar_, PatBasicFWLiteJetAnalyzer_Selector_cfg::outputs, tensorflow::run(), and session_.

Referenced by compute().

◆ setNNVectorVar()

void TauNNId::setNNVectorVar ( )

Definition at line 22 of file TauNNId.cc.

22  {
23  NNvectorVar_.clear();
24  for (int i0 = 0; i0 < fNParticles_; i0++) {
25  NNvectorVar_.push_back(fPt_.get()[i0]); //pT
26  NNvectorVar_.push_back(fEta_.get()[i0]); //dEta from jet axis
27  NNvectorVar_.push_back(fPhi_.get()[i0]); //dPhi from jet axis
28  if (fPt_.get()[i0] == 0) {
29  for (int i1 = 0; i1 < 5; i1++)
30  NNvectorVar_.push_back(0);
31  continue;
32  }
33  NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Photon); // Photon
34  NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Electron); // Electron
35  NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Muon); // Muon
36  NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::NeutralHadron); // Neutral Had
37  NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::ChargedHadron); // Charged Had
38  }
39 }

References l1t::PFCandidate::ChargedHadron, l1t::PFCandidate::Electron, fEta_, fId_, fNParticles_, fPhi_, fPt_, testProducerWithPsetDescEmpty_cfi::i1, l1t::PFCandidate::Muon, l1t::PFCandidate::NeutralHadron, NNvectorVar_, and l1t::PFCandidate::Photon.

Referenced by compute().

Member Data Documentation

◆ fEta_

unique_ptr<float[]> TauNNId::fEta_
private

Definition at line 28 of file TauNNId.h.

Referenced by compute(), setNNVectorVar(), and TauNNId().

◆ fId_

unique_ptr<float[]> TauNNId::fId_
private

Definition at line 30 of file TauNNId.h.

Referenced by compute(), setNNVectorVar(), and TauNNId().

◆ fInput_

std::string TauNNId::fInput_
private

Definition at line 25 of file TauNNId.h.

Referenced by EvaluateNN(), and TauNNId().

◆ fNParticles_

int TauNNId::fNParticles_
private

Definition at line 26 of file TauNNId.h.

Referenced by compute(), setNNVectorVar(), and TauNNId().

◆ fPhi_

unique_ptr<float[]> TauNNId::fPhi_
private

Definition at line 29 of file TauNNId.h.

Referenced by compute(), setNNVectorVar(), and TauNNId().

◆ fPt_

unique_ptr<float[]> TauNNId::fPt_
private

Definition at line 27 of file TauNNId.h.

Referenced by compute(), setNNVectorVar(), and TauNNId().

◆ NNvectorVar_

std::vector<float> TauNNId::NNvectorVar_
private

Definition at line 24 of file TauNNId.h.

Referenced by EvaluateNN(), setNNVectorVar(), and TauNNId().

◆ session_

tensorflow::Session* TauNNId::session_
private

Definition at line 23 of file TauNNId.h.

Referenced by EvaluateNN(), TauNNId(), and ~TauNNId().

l1t::PFCandidate::Photon
Definition: PFCandidate.h:15
tensorflow::createSession
Session * createSession(SessionOptions &sessionOptions)
Definition: TensorFlow.cc:85
mps_fire.i
i
Definition: mps_fire.py:428
input
static const std::string input
Definition: EdmProvDump.cc:48
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
TauNNId::setNNVectorVar
void setNNVectorVar()
Definition: TauNNId.cc:22
PatBasicFWLiteJetAnalyzer_Selector_cfg.outputs
outputs
Definition: PatBasicFWLiteJetAnalyzer_Selector_cfg.py:48
testProducerWithPsetDescEmpty_cfi.i1
i1
Definition: testProducerWithPsetDescEmpty_cfi.py:45
personalPlayback.fp
fp
Definition: personalPlayback.py:523
TauNNId::fEta_
unique_ptr< float[]> fEta_
Definition: TauNNId.h:28
l1t::PFCandidate::Electron
Definition: PFCandidate.h:15
TauNNId::fInput_
std::string fInput_
Definition: TauNNId.h:25
edm::FileInPath
Definition: FileInPath.h:61
tensorflow::closeSession
bool closeSession(Session *&session)
Definition: TensorFlow.cc:198
TauNNId::fPhi_
unique_ptr< float[]> fPhi_
Definition: TauNNId.h:29
SiPixelRawToDigiRegional_cfi.deltaPhi
deltaPhi
Definition: SiPixelRawToDigiRegional_cfi.py:9
utilities.cache
def cache(function)
Definition: utilities.py:3
reco::LeafCandidate::eta
double eta() const final
momentum pseudorapidity
Definition: LeafCandidate.h:152
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
l1t::PFCandidate::ChargedHadron
Definition: PFCandidate.h:15
createfilelist.int
int
Definition: createfilelist.py:10
n_particles_max
static constexpr unsigned int n_particles_max
Definition: TauNNId.cc:6
TauNNId::fId_
unique_ptr< float[]> fId_
Definition: TauNNId.h:30
l1t::PFCandidate::Muon
Definition: PFCandidate.h:15
TauNNId::session_
tensorflow::Session * session_
Definition: TauNNId.h:23
reco::LeafCandidate::phi
double phi() const final
momentum azimuthal angle
Definition: LeafCandidate.h:148
tensorflow::run
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
l1t::PFCandidate
Definition: PFCandidate.h:12
l1t::PFCandidate::NeutralHadron
Definition: PFCandidate.h:15
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
TauNNId::fPt_
unique_ptr< float[]> fPt_
Definition: TauNNId.h:27
TauNNId::fNParticles_
int fNParticles_
Definition: TauNNId.h:26
TauNNId::NNvectorVar_
std::vector< float > NNvectorVar_
Definition: TauNNId.h:24
TauNNId::EvaluateNN
float EvaluateNN()
Definition: TauNNId.cc:40