CMS 3D CMS Logo

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

#include <TauNNIdHW.h>

Public Member Functions

result_t compute (const l1t::PFCandidate &iSeed, std::vector< l1t::PFCandidate > &iParts)
 
result_t EvaluateNN ()
 
void initialize (const std::string &iName, int iNParticles)
 
void SetNNVectorVar ()
 
 TauNNIdHW ()
 
 ~TauNNIdHW ()
 

Public Attributes

unique_ptr< etaphi_t[]> fEta_
 
unique_ptr< id_t[]> fId_
 
std::string fInput_
 
unsigned fNParticles_
 
unique_ptr< etaphi_t[]> fPhi_
 
unique_ptr< pt_t[]> fPt_
 

Private Attributes

std::vector< input_tNNvectorVar_
 

Detailed Description

Definition at line 143 of file TauNNIdHW.h.

Constructor & Destructor Documentation

◆ TauNNIdHW()

TauNNIdHW::TauNNIdHW ( )

Definition at line 4 of file TauNNIdHW.cc.

References NNvectorVar_.

4 { NNvectorVar_.clear(); }
std::vector< input_t > NNvectorVar_
Definition: TauNNIdHW.h:163

◆ ~TauNNIdHW()

TauNNIdHW::~TauNNIdHW ( )

Definition at line 5 of file TauNNIdHW.cc.

5 {}

Member Function Documentation

◆ compute()

result_t TauNNIdHW::compute ( const l1t::PFCandidate iSeed,
std::vector< l1t::PFCandidate > &  iParts 
)

Definition at line 81 of file TauNNIdHW.cc.

References reco::LeafCandidate::eta(), EvaluateNN(), fEta_, fId_, fNParticles_, fPhi_, fPt_, mps_fire::i, dqmiolumiharvest::j, phi, reco::LeafCandidate::phi(), DiDispStaMuonMonitor_cfi::pt, SetNNVectorVar(), and jetUpdater_cfi::sort.

81  {
82  for (unsigned i0 = 0; i0 < fNParticles_; i0++) {
83  fPt_.get()[i0] = 0.;
84  fEta_.get()[i0] = 0.;
85  fPhi_.get()[i0] = 0.;
86  fId_.get()[i0] = 0.;
87  }
88  std::sort(iParts.begin(), iParts.end(), [](l1t::PFCandidate i, l1t::PFCandidate j) {
89  return (pt_t(i.pt()) > pt_t(j.pt()));
90  });
91  for (unsigned int i0 = 0; i0 < iParts.size(); i0++) {
92  if (i0 > fNParticles_)
93  break;
94  fPt_.get()[i0] = pt_t(iParts[i0].pt());
95  fEta_.get()[i0] = etaphi_t(iSeed.eta() - iParts[i0].eta());
96  etaphi_t lDPhi = etaphi_t(iSeed.phi()) - etaphi_t(iParts[i0].phi());
97  etaphi_t lMPI = 3.1415;
98  if (lDPhi > lMPI)
99  lDPhi = lDPhi - lMPI;
100  if (lDPhi < -lMPI)
101  lDPhi = lDPhi + lMPI;
102  fPhi_.get()[i0] = lDPhi;
103  fId_.get()[i0] = id_t(iParts[i0].id());
104  }
105  SetNNVectorVar();
106  return EvaluateNN();
107 }
void SetNNVectorVar()
Definition: TauNNIdHW.cc:15
unique_ptr< id_t[]> fId_
Definition: TauNNIdHW.h:159
unique_ptr< etaphi_t[]> fPhi_
Definition: TauNNIdHW.h:158
unique_ptr< etaphi_t[]> fEta_
Definition: TauNNIdHW.h:157
unsigned fNParticles_
Definition: TauNNIdHW.h:155
result_t EvaluateNN()
Definition: TauNNIdHW.cc:38
ap_uint< 5 > id_t
Definition: TauNNIdHW.h:44
unique_ptr< pt_t[]> fPt_
Definition: TauNNIdHW.h:156
ap_fixed< 10, 4 > etaphi_t
Definition: TauNNIdHW.h:28
double phi() const final
momentum azimuthal angle
ap_ufixed< 16, 14 > pt_t
Definition: TauNNIdHW.h:27
double eta() const final
momentum pseudorapidity

◆ EvaluateNN()

result_t TauNNIdHW::EvaluateNN ( )

Definition at line 38 of file TauNNIdHW.cc.

References b1, b2, b3, b4, data, mps_fire::i, N_INPUTS, N_LAYER_1, N_LAYER_2, N_LAYER_3, N_OUTPUTS, NNvectorVar_, w1, w2, w3, and w4.

Referenced by compute().

38  {
40  for (unsigned int i = 0; i < NNvectorVar_.size(); i++) {
42  }
43 
44  layer1_t layer1_out[N_LAYER_1];
45  layer1_t logits1[N_LAYER_1];
46  nnet::compute_layer<input_t, layer1_t, config1>(data, logits1, w1, b1);
47  nnet::relu<layer1_t, layer1_t, relu_config1>(logits1, layer1_out);
48 
49  layer2_t layer2_out[N_LAYER_2];
50  layer2_t logits2[N_LAYER_2];
51  nnet::compute_layer<layer1_t, layer2_t, config2>(layer1_out, logits2, w2, b2);
52  nnet::relu<layer2_t, layer2_t, relu_config2>(logits2, layer2_out);
53 
54  layer3_t layer3_out[N_LAYER_3];
55  layer3_t logits3[N_LAYER_3];
56  nnet::compute_layer<layer2_t, layer3_t, config3>(layer2_out, logits3, w3, b3);
57  nnet::relu<layer3_t, layer3_t, relu_config3>(logits3, layer3_out);
58 
59  result_t logits4[N_OUTPUTS];
60  nnet::compute_layer<layer3_t, result_t, config4>(layer3_out, logits4, w4, b4);
62  nnet::sigmoid<result_t, result_t, sigmoid_config4>(logits4, res);
63 
64  return res[0];
65 }
weight_default_t b3[10]
Definition: b3.h:9
weight_default_t b1[25]
Definition: b1.h:9
#define N_LAYER_1
common ppss p3p6s2 common epss epspn46 common const1 w2
Definition: inclppp.h:1
weight_default_t b4[1]
Definition: b4.h:9
#define N_INPUTS
Definition: Electron.h:6
ap_fixed< 16, 8 > input_t
common ppss p3p6s2 common epss epspn46 common const1 w4
Definition: inclppp.h:1
ap_fixed< 16, 8 > layer2_t
weight_default_t b2[10]
Definition: b2.h:9
std::vector< input_t > NNvectorVar_
Definition: TauNNIdHW.h:163
#define N_LAYER_3
weight_default_t w1[2000]
Definition: w1.h:9
ap_fixed< 16, 8 > layer3_t
#define N_LAYER_2
common ppss p3p6s2 common epss epspn46 common const1 w3
Definition: inclppp.h:1
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
#define N_OUTPUTS
ap_fixed< 16, 8 > result_t
ap_fixed< 16, 8 > layer1_t

◆ initialize()

void TauNNIdHW::initialize ( const std::string &  iName,
int  iNParticles 
)

Definition at line 7 of file TauNNIdHW.cc.

References fEta_, fId_, fInput_, fNParticles_, fPhi_, and fPt_.

7  {
8  fNParticles_ = iNParticles;
9  fPt_ = std::make_unique<pt_t[]>(fNParticles_);
10  fEta_ = std::make_unique<etaphi_t[]>(fNParticles_);
11  fPhi_ = std::make_unique<etaphi_t[]>(fNParticles_);
12  fId_ = std::make_unique<id_t[]>(fNParticles_);
13  fInput_ = iInput;
14 }
std::string fInput_
Definition: TauNNIdHW.h:154
unique_ptr< id_t[]> fId_
Definition: TauNNIdHW.h:159
unique_ptr< etaphi_t[]> fPhi_
Definition: TauNNIdHW.h:158
unique_ptr< etaphi_t[]> fEta_
Definition: TauNNIdHW.h:157
unsigned fNParticles_
Definition: TauNNIdHW.h:155
unique_ptr< pt_t[]> fPt_
Definition: TauNNIdHW.h:156

◆ SetNNVectorVar()

void TauNNIdHW::SetNNVectorVar ( )

Definition at line 15 of file TauNNIdHW.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().

15  {
16  NNvectorVar_.clear();
17  for (unsigned i0 = 0; i0 < fNParticles_; i0++) {
18  input_t pPt = input_t(fPt_.get()[i0]);
19  input_t pEta = input_t(fEta_.get()[i0]);
20  input_t pPhi = input_t(fPhi_.get()[i0]);
21 
22  NNvectorVar_.push_back(pPt);
23  NNvectorVar_.push_back(pEta);
24  NNvectorVar_.push_back(pPhi);
25  if (fPt_.get()[i0] == 0) {
26  for (unsigned i1 = 0; i1 < 5; i1++)
27  NNvectorVar_.push_back(0);
28  continue;
29  }
30  NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Photon); // Photon
31  NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Electron); // Electron
32  NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Muon); // Muon
33  NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::NeutralHadron); // Neutral Had
34  NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::ChargedHadron); // Charged Had
35  }
36 }
ap_fixed< 16, 8 > input_t
unique_ptr< id_t[]> fId_
Definition: TauNNIdHW.h:159
unique_ptr< etaphi_t[]> fPhi_
Definition: TauNNIdHW.h:158
unique_ptr< etaphi_t[]> fEta_
Definition: TauNNIdHW.h:157
unsigned fNParticles_
Definition: TauNNIdHW.h:155
std::vector< input_t > NNvectorVar_
Definition: TauNNIdHW.h:163
unique_ptr< pt_t[]> fPt_
Definition: TauNNIdHW.h:156

Member Data Documentation

◆ fEta_

unique_ptr<etaphi_t[]> TauNNIdHW::fEta_

Definition at line 157 of file TauNNIdHW.h.

Referenced by compute(), initialize(), and SetNNVectorVar().

◆ fId_

unique_ptr<id_t[]> TauNNIdHW::fId_

Definition at line 159 of file TauNNIdHW.h.

Referenced by compute(), initialize(), and SetNNVectorVar().

◆ fInput_

std::string TauNNIdHW::fInput_

Definition at line 154 of file TauNNIdHW.h.

Referenced by initialize().

◆ fNParticles_

unsigned TauNNIdHW::fNParticles_

Definition at line 155 of file TauNNIdHW.h.

Referenced by compute(), initialize(), and SetNNVectorVar().

◆ fPhi_

unique_ptr<etaphi_t[]> TauNNIdHW::fPhi_

Definition at line 158 of file TauNNIdHW.h.

Referenced by compute(), initialize(), and SetNNVectorVar().

◆ fPt_

unique_ptr<pt_t[]> TauNNIdHW::fPt_

Definition at line 156 of file TauNNIdHW.h.

Referenced by compute(), initialize(), and SetNNVectorVar().

◆ NNvectorVar_

std::vector<input_t> TauNNIdHW::NNvectorVar_
private

Definition at line 163 of file TauNNIdHW.h.

Referenced by EvaluateNN(), SetNNVectorVar(), and TauNNIdHW().