CMS 3D CMS Logo

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

#include <JetId.h>

Public Member Functions

float compute (const l1t::PFJet &iJet, float vz, bool useRawPt)
 
ap_fixed< 16, 6 > computeFixed (const l1t::PFJet &iJet, float vz, bool useRawPt)
 
float EvaluateNN ()
 
ap_fixed< 16, 6 > EvaluateNNFixed ()
 
 JetId (const std::string &iInput, const std::string &iOutput, const std::shared_ptr< hls4mlEmulator::Model > model, int iNParticles)
 
 JetId (const std::string &iInput, const std::string &iOutput, const BJetTFCache *cache, int iNParticles)
 
void setNNVectorVar ()
 
 ~JetId ()=default
 

Private Attributes

unique_ptr< int[]> fCharge_
 
unique_ptr< float[]> fDX_
 
unique_ptr< float[]> fDY_
 
unique_ptr< float[]> fDZ_
 
unique_ptr< float[]> fEta_
 
unique_ptr< int[]> fId_
 
std::string fInput_
 
int fNParticles_
 
std::string fOutput_
 
unique_ptr< float[]> fPhi_
 
unique_ptr< float[]> fPt_
 
std::shared_ptr< hls4mlEmulator::Model > modelRef_
 
std::vector< float > NNvectorVar_
 
tensorflow::Session * sessionRef_
 

Detailed Description

Definition at line 23 of file JetId.h.

Constructor & Destructor Documentation

◆ JetId() [1/2]

JetId::JetId ( const std::string &  iInput,
const std::string &  iOutput,
const std::shared_ptr< hls4mlEmulator::Model >  model,
int  iNParticles 
)

Definition at line 5 of file JetId.cc.

References fCharge_, fDX_, fDY_, fDZ_, fEta_, fId_, fInput_, fNParticles_, fOutput_, fPhi_, fPt_, and NNvectorVar_.

9  : modelRef_(model) {
10  NNvectorVar_.clear();
11  fNParticles_ = iNParticles;
12 
13  fPt_ = std::make_unique<float[]>(fNParticles_);
14  fEta_ = std::make_unique<float[]>(fNParticles_);
15  fPhi_ = std::make_unique<float[]>(fNParticles_);
16  fId_ = std::make_unique<int[]>(fNParticles_);
17  fCharge_ = std::make_unique<int[]>(fNParticles_);
18  fDZ_ = std::make_unique<float[]>(fNParticles_);
19  fDX_ = std::make_unique<float[]>(fNParticles_);
20  fDY_ = std::make_unique<float[]>(fNParticles_);
21  fInput_ = iInput;
22  fOutput_ = iOutput;
23 }
unique_ptr< float[]> fDZ_
Definition: JetId.h:48
unique_ptr< float[]> fDX_
Definition: JetId.h:49
std::vector< float > NNvectorVar_
Definition: JetId.h:39
std::string fInput_
Definition: JetId.h:40
unique_ptr< int[]> fId_
Definition: JetId.h:46
unique_ptr< float[]> fPhi_
Definition: JetId.h:45
unique_ptr< float[]> fEta_
Definition: JetId.h:44
std::string fOutput_
Definition: JetId.h:41
unique_ptr< int[]> fCharge_
Definition: JetId.h:47
unique_ptr< float[]> fPt_
Definition: JetId.h:43
unique_ptr< float[]> fDY_
Definition: JetId.h:50
std::shared_ptr< hls4mlEmulator::Model > modelRef_
Definition: JetId.h:52
int fNParticles_
Definition: JetId.h:42

◆ JetId() [2/2]

JetId::JetId ( const std::string &  iInput,
const std::string &  iOutput,
const BJetTFCache cache,
int  iNParticles 
)

Definition at line 26 of file JetId.cc.

References fCharge_, fDX_, fDY_, fDZ_, fEta_, fId_, fInput_, fNParticles_, fOutput_, fPhi_, fPt_, and NNvectorVar_.

27  : sessionRef_(cache->session) {
28  NNvectorVar_.clear();
29  fNParticles_ = iNParticles;
30 
31  fPt_ = std::make_unique<float[]>(fNParticles_);
32  fEta_ = std::make_unique<float[]>(fNParticles_);
33  fPhi_ = std::make_unique<float[]>(fNParticles_);
34  fId_ = std::make_unique<int[]>(fNParticles_);
35  fCharge_ = std::make_unique<int[]>(fNParticles_);
36  fDZ_ = std::make_unique<float[]>(fNParticles_);
37  fDX_ = std::make_unique<float[]>(fNParticles_);
38  fDY_ = std::make_unique<float[]>(fNParticles_);
39  fInput_ = iInput;
40  fOutput_ = iOutput;
41 }
unique_ptr< float[]> fDZ_
Definition: JetId.h:48
unique_ptr< float[]> fDX_
Definition: JetId.h:49
std::vector< float > NNvectorVar_
Definition: JetId.h:39
std::string fInput_
Definition: JetId.h:40
unique_ptr< int[]> fId_
Definition: JetId.h:46
unique_ptr< float[]> fPhi_
Definition: JetId.h:45
unique_ptr< float[]> fEta_
Definition: JetId.h:44
std::string fOutput_
Definition: JetId.h:41
unique_ptr< int[]> fCharge_
Definition: JetId.h:47
unique_ptr< float[]> fPt_
Definition: JetId.h:43
unique_ptr< float[]> fDY_
Definition: JetId.h:50
def cache(function)
Definition: utilities.py:3
tensorflow::Session * sessionRef_
Definition: JetId.h:51
int fNParticles_
Definition: JetId.h:42

◆ ~JetId()

JetId::~JetId ( )
default

Member Function Documentation

◆ compute()

float JetId::compute ( const l1t::PFJet iJet,
float  vz,
bool  useRawPt 
)

Definition at line 90 of file JetId.cc.

References l1t::PFJet::constituents(), srCondWrite_cfg::deltaPhi, reco::LeafCandidate::eta(), EvaluateNN(), fCharge_, fDX_, fDY_, fDZ_, fEta_, fId_, fNParticles_, fPhi_, fPt_, mps_fire::i, dqmiolumiharvest::j, phi, reco::LeafCandidate::phi(), reco::LeafCandidate::pt(), l1t::PFJet::rawPt(), setNNVectorVar(), jetUpdater_cfi::sort, and btvMC_cff::vz.

90  {
91  for (int i0 = 0; i0 < fNParticles_; i0++) {
92  fPt_.get()[i0] = 0;
93  fEta_.get()[i0] = 0;
94  fPhi_.get()[i0] = 0;
95  fId_.get()[i0] = 0;
96  fCharge_.get()[i0] = 0;
97  fDZ_.get()[i0] = 0;
98  fDX_.get()[i0] = 0;
99  fDY_.get()[i0] = 0;
100  }
101  auto iParts = iJet.constituents();
102  std::sort(iParts.begin(), iParts.end(), [](edm::Ptr<l1t::PFCandidate> i, edm::Ptr<l1t::PFCandidate> j) {
103  return (i->pt() > j->pt());
104  });
105  float jetpt = useRawPt ? iJet.rawPt() : iJet.pt();
106  for (unsigned int i0 = 0; i0 < iParts.size(); i0++) {
107  if (i0 >= (unsigned int)fNParticles_)
108  break;
109  fPt_.get()[i0] = iParts[i0]->pt() / jetpt;
110  fEta_.get()[i0] = iParts[i0]->eta() - iJet.eta();
111  fPhi_.get()[i0] = deltaPhi(iParts[i0]->phi(), iJet.phi());
112  fId_.get()[i0] = iParts[i0]->id();
113  fCharge_.get()[i0] = iParts[i0]->charge();
114  if (iParts[i0]->pfTrack().isNonnull()) {
115  fDX_.get()[i0] = iParts[i0]->pfTrack()->vx();
116  fDY_.get()[i0] = iParts[i0]->pfTrack()->vy();
117  fDZ_.get()[i0] = iParts[i0]->pfTrack()->vz() - vz;
118  }
119  }
120  setNNVectorVar();
121  return EvaluateNN();
122 }
unique_ptr< float[]> fDZ_
Definition: JetId.h:48
double pt() const final
transverse momentum
unique_ptr< float[]> fDX_
Definition: JetId.h:49
void setNNVectorVar()
Definition: JetId.cc:43
unique_ptr< int[]> fId_
Definition: JetId.h:46
float rawPt() const
Definition: PFJet.h:27
unique_ptr< float[]> fPhi_
Definition: JetId.h:45
unique_ptr< float[]> fEta_
Definition: JetId.h:44
const Constituents & constituents() const
constituent information. note that this is not going to be available in the hardware! ...
Definition: PFJet.h:30
unique_ptr< int[]> fCharge_
Definition: JetId.h:47
float EvaluateNN()
Definition: JetId.cc:66
unique_ptr< float[]> fPt_
Definition: JetId.h:43
unique_ptr< float[]> fDY_
Definition: JetId.h:50
double phi() const final
momentum azimuthal angle
int fNParticles_
Definition: JetId.h:42
double eta() const final
momentum pseudorapidity

◆ computeFixed()

ap_fixed< 16, 6 > JetId::computeFixed ( const l1t::PFJet iJet,
float  vz,
bool  useRawPt 
)

Definition at line 124 of file JetId.cc.

References l1t::PFJet::constituents(), srCondWrite_cfg::deltaPhi, reco::LeafCandidate::eta(), EvaluateNNFixed(), fCharge_, fDX_, fDY_, fDZ_, fEta_, fId_, fNParticles_, fPhi_, fPt_, mps_fire::i, dqmiolumiharvest::j, phi, reco::LeafCandidate::phi(), reco::LeafCandidate::pt(), l1t::PFJet::rawPt(), setNNVectorVar(), jetUpdater_cfi::sort, and btvMC_cff::vz.

124  {
125  for (int i0 = 0; i0 < fNParticles_; i0++) {
126  fPt_.get()[i0] = 0;
127  fEta_.get()[i0] = 0;
128  fPhi_.get()[i0] = 0;
129  fId_.get()[i0] = 0;
130  fCharge_.get()[i0] = 0;
131  fDZ_.get()[i0] = 0;
132  fDX_.get()[i0] = 0;
133  fDY_.get()[i0] = 0;
134  }
135  auto iParts = iJet.constituents();
136  std::sort(iParts.begin(), iParts.end(), [](edm::Ptr<l1t::PFCandidate> i, edm::Ptr<l1t::PFCandidate> j) {
137  return (i->pt() > j->pt());
138  });
139  float jetpt = useRawPt ? iJet.rawPt() : iJet.pt();
140  for (unsigned int i0 = 0; i0 < iParts.size(); i0++) {
141  if (i0 >= (unsigned int)fNParticles_)
142  break;
143  fPt_.get()[i0] = iParts[i0]->pt() / jetpt;
144  fEta_.get()[i0] = iParts[i0]->eta() - iJet.eta();
145  fPhi_.get()[i0] = deltaPhi(iParts[i0]->phi(), iJet.phi());
146  fId_.get()[i0] = iParts[i0]->id();
147  fCharge_.get()[i0] = iParts[i0]->charge();
148  if (iParts[i0]->pfTrack().isNonnull()) {
149  fDX_.get()[i0] = iParts[i0]->pfTrack()->vx();
150  fDY_.get()[i0] = iParts[i0]->pfTrack()->vy();
151  fDZ_.get()[i0] = iParts[i0]->pfTrack()->vz() - vz;
152  }
153  }
154  setNNVectorVar();
155  return EvaluateNNFixed();
156 }
ap_fixed< 16, 6 > EvaluateNNFixed()
Definition: JetId.cc:76
unique_ptr< float[]> fDZ_
Definition: JetId.h:48
double pt() const final
transverse momentum
unique_ptr< float[]> fDX_
Definition: JetId.h:49
void setNNVectorVar()
Definition: JetId.cc:43
unique_ptr< int[]> fId_
Definition: JetId.h:46
float rawPt() const
Definition: PFJet.h:27
unique_ptr< float[]> fPhi_
Definition: JetId.h:45
unique_ptr< float[]> fEta_
Definition: JetId.h:44
const Constituents & constituents() const
constituent information. note that this is not going to be available in the hardware! ...
Definition: PFJet.h:30
unique_ptr< int[]> fCharge_
Definition: JetId.h:47
unique_ptr< float[]> fPt_
Definition: JetId.h:43
unique_ptr< float[]> fDY_
Definition: JetId.h:50
double phi() const final
momentum azimuthal angle
int fNParticles_
Definition: JetId.h:42
double eta() const final
momentum pseudorapidity

◆ EvaluateNN()

float JetId::EvaluateNN ( )

Definition at line 66 of file JetId.cc.

References fInput_, ALCARECOEcalPhiSym_cff::float, fOutput_, mps_fire::i, input, createfilelist::int, NNvectorVar_, PatBasicFWLiteJetAnalyzer_Selector_cfg::outputs, tensorflow::run(), and sessionRef_.

Referenced by compute().

66  {
67  tensorflow::Tensor input(tensorflow::DT_FLOAT, {1, (unsigned int)NNvectorVar_.size(), 1});
68  for (unsigned int i = 0; i < NNvectorVar_.size(); i++) {
69  input.tensor<float, 3>()(0, i, 0) = float(NNvectorVar_[i]);
70  }
71  std::vector<tensorflow::Tensor> outputs;
73  return outputs[0].matrix<float>()(0, 0);
74 } //end EvaluateNN
std::vector< float > NNvectorVar_
Definition: JetId.h:39
std::string fInput_
Definition: JetId.h:40
static std::string const input
Definition: EdmProvDump.cc:50
void run(Session *session, const NamedTensorList &inputs, const std::vector< std::string > &outputNames, std::vector< Tensor > *outputs, const thread::ThreadPoolOptions &threadPoolOptions)
Definition: TensorFlow.cc:271
std::string fOutput_
Definition: JetId.h:41
tensorflow::Session * sessionRef_
Definition: JetId.h:51

◆ EvaluateNNFixed()

ap_fixed< 16, 6 > JetId::EvaluateNNFixed ( )

Definition at line 76 of file JetId.cc.

References mps_fire::i, modelRef_, and NNvectorVar_.

Referenced by computeFixed().

76  {
77  ap_fixed<16, 6> modelInput[140] = {};
78  for (unsigned int i = 0; i < NNvectorVar_.size(); i++) {
79  modelInput[i] = NNvectorVar_[i];
80  }
81  ap_fixed<16, 6> modelResult[1] = {-1};
82 
83  modelRef_->prepare_input(modelInput);
84  modelRef_->predict();
85  modelRef_->read_result(modelResult);
86  ap_fixed<16, 6> modelResult_ = modelResult[0];
87  return modelResult_;
88 } //end EvaluateNNFixed
std::vector< float > NNvectorVar_
Definition: JetId.h:39
std::shared_ptr< hls4mlEmulator::Model > modelRef_
Definition: JetId.h:52

◆ setNNVectorVar()

void JetId::setNNVectorVar ( )

Definition at line 43 of file JetId.cc.

References l1t::PFCandidate::ChargedHadron, l1t::PFCandidate::Electron, fCharge_, fDX_, fDY_, fDZ_, fEta_, fId_, fNParticles_, fPhi_, fPt_, Matriplex::hypot(), testProducerWithPsetDescEmpty_cfi::i1, l1t::PFCandidate::Muon, l1t::PFCandidate::NeutralHadron, NNvectorVar_, and l1t::PFCandidate::Photon.

Referenced by compute(), and computeFixed().

43  {
44  NNvectorVar_.clear();
45  for (int i0 = 0; i0 < fNParticles_; i0++) {
46  if (fPt_.get()[i0] == 0) {
47  for (int i1 = 0; i1 < 13; i1++)
48  NNvectorVar_.push_back(0);
49  continue;
50  }
51  NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Electron && fCharge_.get()[i0] < 0); // Electron
52  NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Electron && fCharge_.get()[i0] > 0); // Positron
53  NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Muon && fCharge_.get()[i0] < 0); // Muon
54  NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Muon && fCharge_.get()[i0] > 0); // Anti-Muon
55  NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Photon); // Photon
56  NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::NeutralHadron); // Neutral Had
57  NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::ChargedHadron && fCharge_.get()[i0] < 0); // Pion
58  NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::ChargedHadron && fCharge_.get()[i0] > 0); // Anti-Pion
59  NNvectorVar_.push_back(fDZ_.get()[i0]); //dZ
60  NNvectorVar_.push_back(std::hypot(fDX_.get()[i0], fDY_.get()[i0])); //d0
61  NNvectorVar_.push_back(fPt_.get()[i0]); //pT as a fraction of jet pT
62  NNvectorVar_.push_back(fEta_.get()[i0]); //dEta from jet axis
63  NNvectorVar_.push_back(fPhi_.get()[i0]); //dPhi from jet axis
64  }
65 }
unique_ptr< float[]> fDZ_
Definition: JetId.h:48
MPlex< T, D1, D2, N > hypot(const MPlex< T, D1, D2, N > &a, const MPlex< T, D1, D2, N > &b)
Definition: Matriplex.h:616
unique_ptr< float[]> fDX_
Definition: JetId.h:49
std::vector< float > NNvectorVar_
Definition: JetId.h:39
unique_ptr< int[]> fId_
Definition: JetId.h:46
unique_ptr< float[]> fPhi_
Definition: JetId.h:45
unique_ptr< float[]> fEta_
Definition: JetId.h:44
unique_ptr< int[]> fCharge_
Definition: JetId.h:47
unique_ptr< float[]> fPt_
Definition: JetId.h:43
unique_ptr< float[]> fDY_
Definition: JetId.h:50
int fNParticles_
Definition: JetId.h:42

Member Data Documentation

◆ fCharge_

unique_ptr<int[]> JetId::fCharge_
private

Definition at line 47 of file JetId.h.

Referenced by compute(), computeFixed(), JetId(), and setNNVectorVar().

◆ fDX_

unique_ptr<float[]> JetId::fDX_
private

Definition at line 49 of file JetId.h.

Referenced by compute(), computeFixed(), JetId(), and setNNVectorVar().

◆ fDY_

unique_ptr<float[]> JetId::fDY_
private

Definition at line 50 of file JetId.h.

Referenced by compute(), computeFixed(), JetId(), and setNNVectorVar().

◆ fDZ_

unique_ptr<float[]> JetId::fDZ_
private

Definition at line 48 of file JetId.h.

Referenced by compute(), computeFixed(), JetId(), and setNNVectorVar().

◆ fEta_

unique_ptr<float[]> JetId::fEta_
private

Definition at line 44 of file JetId.h.

Referenced by compute(), computeFixed(), JetId(), and setNNVectorVar().

◆ fId_

unique_ptr<int[]> JetId::fId_
private

Definition at line 46 of file JetId.h.

Referenced by compute(), computeFixed(), JetId(), and setNNVectorVar().

◆ fInput_

std::string JetId::fInput_
private

Definition at line 40 of file JetId.h.

Referenced by EvaluateNN(), and JetId().

◆ fNParticles_

int JetId::fNParticles_
private

Definition at line 42 of file JetId.h.

Referenced by compute(), computeFixed(), JetId(), and setNNVectorVar().

◆ fOutput_

std::string JetId::fOutput_
private

Definition at line 41 of file JetId.h.

Referenced by EvaluateNN(), and JetId().

◆ fPhi_

unique_ptr<float[]> JetId::fPhi_
private

Definition at line 45 of file JetId.h.

Referenced by compute(), computeFixed(), JetId(), and setNNVectorVar().

◆ fPt_

unique_ptr<float[]> JetId::fPt_
private

Definition at line 43 of file JetId.h.

Referenced by compute(), computeFixed(), JetId(), and setNNVectorVar().

◆ modelRef_

std::shared_ptr<hls4mlEmulator::Model> JetId::modelRef_
private

Definition at line 52 of file JetId.h.

Referenced by EvaluateNNFixed().

◆ NNvectorVar_

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

Definition at line 39 of file JetId.h.

Referenced by EvaluateNN(), EvaluateNNFixed(), JetId(), and setNNVectorVar().

◆ sessionRef_

tensorflow::Session* JetId::sessionRef_
private

Definition at line 51 of file JetId.h.

Referenced by EvaluateNN().