CMS 3D CMS Logo

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

#include <TauNNIdHW.h>

Public Member Functions

Tau_NN_Result compute (const l1t::PFCandidate &iSeed, std::vector< l1t::PFCandidate > &iParts)
 
Tau_NN_Result EvaluateNN ()
 
void initialize (const std::string &iName, int iNParticles)
 
input_tNNVectorVar ()
 
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 135 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:156

◆ ~TauNNIdHW()

TauNNIdHW::~TauNNIdHW ( )

Definition at line 5 of file TauNNIdHW.cc.

5 {}

Member Function Documentation

◆ compute()

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

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

111  {
112  // Initialize the input vector
113  for (unsigned i0 = 0; i0 < fNParticles_; i0++) {
114  fPt_.get()[i0] = 0.;
115  fEta_.get()[i0] = 0.;
116  fPhi_.get()[i0] = 0.;
117  fId_.get()[i0] = 0.;
118  }
119 
120  // Sort the candidates by pT
121  std::sort(iParts.begin(), iParts.end(), [](l1t::PFCandidate i, l1t::PFCandidate j) {
122  return (pt_t(i.pt()) > pt_t(j.pt()));
123  });
124 
125  // Compute the values w.r.t to the seeds
126  for (unsigned int i0 = 0; i0 < iParts.size(); i0++) {
127  if (i0 >= fNParticles_)
128  break;
129 
130  fPt_.get()[i0] = pt_t(iParts[i0].pt());
131  fEta_.get()[i0] = etaphi_t(iSeed.eta() - iParts[i0].eta());
132  etaphi_t lDPhi = etaphi_t(iSeed.phi()) - etaphi_t(iParts[i0].phi());
133  etaphi_t lMPI = 3.1415;
134 
135  if (lDPhi > lMPI)
136  lDPhi = lDPhi - lMPI;
137  if (lDPhi < -lMPI)
138  lDPhi = lDPhi + lMPI;
139 
140  fPhi_.get()[i0] = lDPhi;
141  fId_.get()[i0] = id_t(iParts[i0].id());
142  }
143 
144  // Set the inputs
145  SetNNVectorVar();
146 
147  // Return the N outputs with the inputs
148  return EvaluateNN();
149 }
void SetNNVectorVar()
Definition: TauNNIdHW.cc:17
unique_ptr< id_t[]> fId_
Definition: TauNNIdHW.h:152
unique_ptr< etaphi_t[]> fPhi_
Definition: TauNNIdHW.h:151
unique_ptr< etaphi_t[]> fEta_
Definition: TauNNIdHW.h:150
unsigned fNParticles_
Definition: TauNNIdHW.h:148
Tau_NN_Result EvaluateNN()
Definition: TauNNIdHW.cc:41
ap_uint< 5 > id_t
Definition: TauNNIdHW.h:36
unique_ptr< pt_t[]> fPt_
Definition: TauNNIdHW.h:149
ap_fixed< 10, 4 > etaphi_t
Definition: TauNNIdHW.h:14
double phi() const final
momentum azimuthal angle
ap_ufixed< 16, 14 > pt_t
Definition: TauNNIdHW.h:13
double eta() const final
momentum pseudorapidity

◆ EvaluateNN()

Tau_NN_Result TauNNIdHW::EvaluateNN ( )

Definition at line 41 of file TauNNIdHW.cc.

References b11, b14, b17, b2, b20, b5, b8, mps_fire::i, N_INPUT_1_1, N_LAYER_11, N_LAYER_14, N_LAYER_17, N_LAYER_2, N_LAYER_20, N_LAYER_5, N_LAYER_8, Tau_NN_Result::nn_pt_correction, NNvectorVar_, w11, w14, w17, w2, w20, w5, and w8.

Referenced by compute().

41  {
42  input_t model_input[N_INPUT_1_1];
43  for (unsigned int i = 0; i < NNvectorVar_.size(); i++) {
44  model_input[i] = input_t(NNvectorVar_[i]);
45  }
46 
47  layer2_t layer2_out[N_LAYER_2];
48  nnet::dense<input_t, layer2_t, config2>(model_input, layer2_out, w2, b2); // Dense_1
49 
50  layer4_t layer4_out[N_LAYER_2];
51  nnet::relu<layer2_t, layer4_t, relu_config4>(layer2_out, layer4_out); // relu_1
52 
53  layer5_t layer5_out[N_LAYER_5];
54  nnet::dense<layer4_t, layer5_t, config5>(layer4_out, layer5_out, w5, b5); // Dense_2
55 
56  layer7_t layer7_out[N_LAYER_5];
57  nnet::relu<layer5_t, layer7_t, relu_config7>(layer5_out, layer7_out); // relu_2
58 
59  layer8_t layer8_out[N_LAYER_8];
60  nnet::dense<layer7_t, layer8_t, config8>(layer7_out, layer8_out, w8, b8); // Dense_3
61 
62  layer10_t layer10_out[N_LAYER_8];
63  nnet::relu<layer8_t, layer10_t, relu_config10>(layer8_out, layer10_out); // relu_3
64 
65  layer11_t layer11_out[N_LAYER_11];
66  nnet::dense<layer10_t, layer11_t, config11>(layer10_out, layer11_out, w11, b11); // Dense_4
67 
68  layer13_t layer13_out[N_LAYER_11];
69  nnet::relu<layer11_t, layer13_t, relu_config13>(layer11_out, layer13_out); // relu_4
70 
71  layer14_t layer14_out[N_LAYER_14];
72  nnet::dense<layer13_t, layer14_t, config14>(layer13_out, layer14_out, w14, b14); // Dense_5
73 
74  layer16_t layer16_out[N_LAYER_14];
75  nnet::relu<layer14_t, layer16_t, relu_config16>(layer14_out, layer16_out); // relu_5
76 
77  layer17_t layer17_out[N_LAYER_17];
78  nnet::dense<layer16_t, layer17_t, config17>(layer16_out, layer17_out, w17, b17); // Dense_6
79 
80  result_t layer19_out[N_LAYER_17];
81  nnet::sigmoid<layer17_t, result_t, sigmoid_config19>(layer17_out, layer19_out); // jetID_output
82 
83  result_t layer20_out[N_LAYER_20];
84  nnet::dense<layer16_t, result_t, config20>(layer16_out, layer20_out, w20, b20); // pT_output
85 
86  // Return both pT correction and the NN ID
87  Tau_NN_Result nn_out;
88  nn_out.nn_pt_correction = layer20_out[0];
89  nn_out.nn_id = layer19_out[0];
90 
91  return nn_out;
92 }
bias5_t b5[25]
Definition: b5.h:9
bias14_t b14[10]
Definition: b14.h:9
common ppss p3p6s2 common epss epspn46 common const1 w2
Definition: inclppp.h:1
bias11_t b11[15]
Definition: b11.h:9
ap_fixed< 16, 6 > layer11_t
Definition: defines.h:48
common ppss p3p6s2 common epss epspn46 common const1 w8
Definition: inclppp.h:1
#define N_LAYER_11
Definition: defines.h:19
bias20_t b20[1]
Definition: b20.h:9
bias8_t b8[15]
Definition: b8.h:9
common ppss p3p6s2 common epss epspn46 common const1 w11
Definition: inclppp.h:1
ap_fixed< 16, 6 > layer5_t
Definition: defines.h:36
common ppss p3p6s2 common epss epspn46 common const1 w20
Definition: inclppp.h:1
ap_ufixed< 9, 0, AP_RND_CONV, AP_SAT > layer4_t
Definition: defines.h:34
ap_fixed< 16, 6 > result_t
Definition: defines.h:64
common ppss p3p6s2 common epss epspn46 common const1 w14
Definition: inclppp.h:1
#define N_LAYER_14
Definition: defines.h:21
ap_ufixed< 9, 0, AP_RND_CONV, AP_SAT > layer7_t
Definition: defines.h:40
#define N_LAYER_17
Definition: defines.h:23
ap_ufixed< 9, 0, AP_RND_CONV, AP_SAT > layer13_t
Definition: defines.h:52
bias2_t b2[25]
Definition: b2.h:9
ap_fixed< 16, 6 > layer2_t
Definition: defines.h:30
std::vector< input_t > NNvectorVar_
Definition: TauNNIdHW.h:156
ap_ufixed< 9, 0, AP_RND_CONV, AP_SAT > layer16_t
Definition: defines.h:58
ap_fixed< 16, 10 > input_t
Definition: defines.h:27
ap_fixed< 16, 6 > layer14_t
Definition: defines.h:54
#define N_LAYER_5
Definition: defines.h:15
#define N_LAYER_2
Definition: defines.h:13
#define N_INPUT_1_1
Definition: defines.h:11
#define N_LAYER_20
Definition: defines.h:24
common ppss p3p6s2 common epss epspn46 common const1 w17
Definition: inclppp.h:1
ap_fixed< 16, 6 > layer8_t
Definition: defines.h:42
result_t nn_pt_correction
Definition: TauNNIdHW.h:18
bias17_t b17[1]
Definition: b17.h:9
common ppss p3p6s2 common epss epspn46 common const1 w5
Definition: inclppp.h:1
#define N_LAYER_8
Definition: defines.h:17
ap_ufixed< 9, 0, AP_RND_CONV, AP_SAT > layer10_t
Definition: defines.h:46
ap_fixed< 16, 6 > layer17_t
Definition: defines.h:60

◆ 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:147
unique_ptr< id_t[]> fId_
Definition: TauNNIdHW.h:152
unique_ptr< etaphi_t[]> fPhi_
Definition: TauNNIdHW.h:151
unique_ptr< etaphi_t[]> fEta_
Definition: TauNNIdHW.h:150
unsigned fNParticles_
Definition: TauNNIdHW.h:148
unique_ptr< pt_t[]> fPt_
Definition: TauNNIdHW.h:149

◆ NNVectorVar()

input_t* TauNNIdHW::NNVectorVar ( )
inline

Definition at line 142 of file TauNNIdHW.h.

References NNvectorVar_.

142 { return NNvectorVar_.data(); }
std::vector< input_t > NNvectorVar_
Definition: TauNNIdHW.h:156

◆ SetNNVectorVar()

void TauNNIdHW::SetNNVectorVar ( )

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

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

Member Data Documentation

◆ fEta_

unique_ptr<etaphi_t[]> TauNNIdHW::fEta_

Definition at line 150 of file TauNNIdHW.h.

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

◆ fId_

unique_ptr<id_t[]> TauNNIdHW::fId_

Definition at line 152 of file TauNNIdHW.h.

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

◆ fInput_

std::string TauNNIdHW::fInput_

Definition at line 147 of file TauNNIdHW.h.

Referenced by initialize().

◆ fNParticles_

unsigned TauNNIdHW::fNParticles_

Definition at line 148 of file TauNNIdHW.h.

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

◆ fPhi_

unique_ptr<etaphi_t[]> TauNNIdHW::fPhi_

Definition at line 151 of file TauNNIdHW.h.

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

◆ fPt_

unique_ptr<pt_t[]> TauNNIdHW::fPt_

Definition at line 149 of file TauNNIdHW.h.

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

◆ NNvectorVar_

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

Definition at line 156 of file TauNNIdHW.h.

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