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 tensorflow::Session *session, 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_
 
const tensorflow::Session * session_
 

Detailed Description

Definition at line 8 of file TauNNId.h.

Constructor & Destructor Documentation

◆ TauNNId()

TauNNId::TauNNId ( const std::string &  iInput,
const tensorflow::Session *  session,
const std::string &  iWeightFile,
int  iNParticles 
)

Definition at line 8 of file TauNNId.cc.

References fEta_, fId_, fInput_, fNParticles_, personalPlayback::fp, fPhi_, fPt_, and NNvectorVar_.

12  : session_(session) {
13  NNvectorVar_.clear();
14  edm::FileInPath fp(iWeightFile);
15  fNParticles_ = iNParticles;
16 
17  fPt_ = std::make_unique<float[]>(fNParticles_);
18  fEta_ = std::make_unique<float[]>(fNParticles_);
19  fPhi_ = std::make_unique<float[]>(fNParticles_);
20  fId_ = std::make_unique<float[]>(fNParticles_);
21  fInput_ = iInput;
22 }
const tensorflow::Session * session_
Definition: TauNNId.h:21
unique_ptr< float[]> fPhi_
Definition: TauNNId.h:27
int fNParticles_
Definition: TauNNId.h:24
unique_ptr< float[]> fId_
Definition: TauNNId.h:28
std::vector< float > NNvectorVar_
Definition: TauNNId.h:22
unique_ptr< float[]> fPt_
Definition: TauNNId.h:25
std::string fInput_
Definition: TauNNId.h:23
unique_ptr< float[]> fEta_
Definition: TauNNId.h:26

◆ ~TauNNId()

TauNNId::~TauNNId ( )
inline

Definition at line 14 of file TauNNId.h.

14 {};

Member Function Documentation

◆ compute()

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

Definition at line 53 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.

53  {
54  for (int i0 = 0; i0 < fNParticles_; i0++) {
55  fPt_.get()[i0] = 0;
56  fEta_.get()[i0] = 0;
57  fPhi_.get()[i0] = 0;
58  fId_.get()[i0] = 0;
59  }
60  std::sort(iParts.begin(), iParts.end(), [](l1t::PFCandidate i, l1t::PFCandidate j) { return (i.pt() > j.pt()); });
61  for (unsigned int i0 = 0; i0 < iParts.size(); i0++) {
62  if (i0 > n_particles_max || i0 >= (unsigned int)fNParticles_)
63  break;
64  fPt_.get()[i0] = iParts[i0].pt();
65  fEta_.get()[i0] = iSeed.eta() - iParts[i0].eta();
66  fPhi_.get()[i0] = deltaPhi(iSeed.phi(), iParts[i0].phi());
67  fId_.get()[i0] = iParts[i0].id();
68  }
70  return EvaluateNN();
71 }
unique_ptr< float[]> fPhi_
Definition: TauNNId.h:27
static constexpr unsigned int n_particles_max
Definition: TauNNId.cc:6
int fNParticles_
Definition: TauNNId.h:24
unique_ptr< float[]> fId_
Definition: TauNNId.h:28
void setNNVectorVar()
Definition: TauNNId.cc:24
unique_ptr< float[]> fPt_
Definition: TauNNId.h:25
float EvaluateNN()
Definition: TauNNId.cc:42
double phi() const final
momentum azimuthal angle
unique_ptr< float[]> fEta_
Definition: TauNNId.h:26
double eta() const final
momentum pseudorapidity

◆ EvaluateNN()

float TauNNId::EvaluateNN ( )

Definition at line 42 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().

42  {
43  tensorflow::Tensor input(tensorflow::DT_FLOAT,
44  {1, (unsigned int)NNvectorVar_.size()}); //was {1,35} but get size mismatch, CHECK
45  for (unsigned int i = 0; i < NNvectorVar_.size(); i++) {
46  input.matrix<float>()(0, i) = float(NNvectorVar_[i]);
47  }
48  std::vector<tensorflow::Tensor> outputs;
49  tensorflow::run(session_, {{fInput_, input}}, {"dense_4/Sigmoid:0"}, &outputs);
50  return outputs[0].matrix<float>()(0, 0);
51 } //end EvaluateNN
const tensorflow::Session * session_
Definition: TauNNId.h:21
static std::string const input
Definition: EdmProvDump.cc:50
std::vector< float > NNvectorVar_
Definition: TauNNId.h:22
void run(Session *session, const NamedTensorList &inputs, const std::vector< std::string > &outputNames, std::vector< Tensor > *outputs, const thread::ThreadPoolOptions &threadPoolOptions)
Definition: TensorFlow.cc:286
std::string fInput_
Definition: TauNNId.h:23

◆ setNNVectorVar()

void TauNNId::setNNVectorVar ( )

Definition at line 24 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().

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

Member Data Documentation

◆ fEta_

unique_ptr<float[]> TauNNId::fEta_
private

Definition at line 26 of file TauNNId.h.

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

◆ fId_

unique_ptr<float[]> TauNNId::fId_
private

Definition at line 28 of file TauNNId.h.

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

◆ fInput_

std::string TauNNId::fInput_
private

Definition at line 23 of file TauNNId.h.

Referenced by EvaluateNN(), and TauNNId().

◆ fNParticles_

int TauNNId::fNParticles_
private

Definition at line 24 of file TauNNId.h.

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

◆ fPhi_

unique_ptr<float[]> TauNNId::fPhi_
private

Definition at line 27 of file TauNNId.h.

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

◆ fPt_

unique_ptr<float[]> TauNNId::fPt_
private

Definition at line 25 of file TauNNId.h.

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

◆ NNvectorVar_

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

Definition at line 22 of file TauNNId.h.

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

◆ session_

const tensorflow::Session* TauNNId::session_
private

Definition at line 21 of file TauNNId.h.

Referenced by EvaluateNN().