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.

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

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 }
Session * createSession(SessionOptions &sessionOptions)
Definition: TensorFlow.cc:85
unique_ptr< float[]> fPhi_
Definition: TauNNId.h:29
int fNParticles_
Definition: TauNNId.h:26
unique_ptr< float[]> fId_
Definition: TauNNId.h:30
std::vector< float > NNvectorVar_
Definition: TauNNId.h:24
unique_ptr< float[]> fPt_
Definition: TauNNId.h:27
tensorflow::Session * session_
Definition: TauNNId.h:23
std::string fInput_
Definition: TauNNId.h:25
def cache(function)
Definition: utilities.py:3
unique_ptr< float[]> fEta_
Definition: TauNNId.h:28

◆ ~TauNNId()

TauNNId::~TauNNId ( )

Definition at line 21 of file TauNNId.cc.

References tensorflow::closeSession(), and session_.

bool closeSession(Session *&session)
Definition: TensorFlow.cc:198
tensorflow::Session * session_
Definition: TauNNId.h:23

Member Function Documentation

◆ compute()

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

Definition at line 51 of file TauNNId.cc.

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.

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 }
unique_ptr< float[]> fPhi_
Definition: TauNNId.h:29
static constexpr unsigned int n_particles_max
Definition: TauNNId.cc:6
int fNParticles_
Definition: TauNNId.h:26
unique_ptr< float[]> fId_
Definition: TauNNId.h:30
void setNNVectorVar()
Definition: TauNNId.cc:22
unique_ptr< float[]> fPt_
Definition: TauNNId.h:27
float EvaluateNN()
Definition: TauNNId.cc:40
double phi() const final
momentum azimuthal angle
unique_ptr< float[]> fEta_
Definition: TauNNId.h:28
double eta() const final
momentum pseudorapidity

◆ EvaluateNN()

float TauNNId::EvaluateNN ( )

Definition at line 40 of file TauNNId.cc.

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

Referenced by compute().

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
static std::string const input
Definition: EdmProvDump.cc:47
std::vector< float > NNvectorVar_
Definition: TauNNId.h:24
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
tensorflow::Session * session_
Definition: TauNNId.h:23
std::string fInput_
Definition: TauNNId.h:25

◆ setNNVectorVar()

void TauNNId::setNNVectorVar ( )

Definition at line 22 of file TauNNId.cc.

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

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 }
unique_ptr< float[]> fPhi_
Definition: TauNNId.h:29
int fNParticles_
Definition: TauNNId.h:26
unique_ptr< float[]> fId_
Definition: TauNNId.h:30
std::vector< float > NNvectorVar_
Definition: TauNNId.h:24
unique_ptr< float[]> fPt_
Definition: TauNNId.h:27
unique_ptr< float[]> fEta_
Definition: TauNNId.h:28

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