CMS 3D CMS Logo

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

#include <BJetId.h>

Public Member Functions

 BJetId (const std::string &iInput, const std::string &iOutput, const BJetTFCache *cache, int iNParticles)
 
float compute (const l1t::PFJet &iJet, float vz, bool useRawPt)
 
float EvaluateNN ()
 
void setNNVectorVar ()
 
 ~BJetId ()
 

Private Attributes

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

Detailed Description

Definition at line 18 of file BJetId.h.

Constructor & Destructor Documentation

◆ BJetId()

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

Definition at line 5 of file BJetId.cc.

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

6  : sessionRef_(cache->session) {
7  NNvectorVar_.clear();
8  fNParticles_ = iNParticles;
9 
10  fPt_ = std::make_unique<float[]>(fNParticles_);
11  fEta_ = std::make_unique<float[]>(fNParticles_);
12  fPhi_ = std::make_unique<float[]>(fNParticles_);
13  fId_ = std::make_unique<float[]>(fNParticles_);
14  fCharge_ = std::make_unique<int[]>(fNParticles_);
15  fDZ_ = std::make_unique<float[]>(fNParticles_);
16  fDX_ = std::make_unique<float[]>(fNParticles_);
17  fDY_ = std::make_unique<float[]>(fNParticles_);
18  fInput_ = iInput;
19  fOutput_ = iOutput;
20 }
int fNParticles_
Definition: BJetId.h:31
tensorflow::Session * sessionRef_
Definition: BJetId.h:40
unique_ptr< float[]> fPhi_
Definition: BJetId.h:34
std::string fOutput_
Definition: BJetId.h:30
std::string fInput_
Definition: BJetId.h:29
unique_ptr< int[]> fCharge_
Definition: BJetId.h:36
unique_ptr< float[]> fId_
Definition: BJetId.h:35
unique_ptr< float[]> fDX_
Definition: BJetId.h:38
unique_ptr< float[]> fDZ_
Definition: BJetId.h:37
unique_ptr< float[]> fDY_
Definition: BJetId.h:39
unique_ptr< float[]> fEta_
Definition: BJetId.h:33
def cache(function)
Definition: utilities.py:3
unique_ptr< float[]> fPt_
Definition: BJetId.h:32
std::vector< float > NNvectorVar_
Definition: BJetId.h:28

◆ ~BJetId()

BJetId::~BJetId ( )

Definition at line 22 of file BJetId.cc.

22 {}

Member Function Documentation

◆ compute()

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

Definition at line 56 of file BJetId.cc.

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

56  {
57  for (int i0 = 0; i0 < fNParticles_; i0++) {
58  fPt_.get()[i0] = 0;
59  fEta_.get()[i0] = 0;
60  fPhi_.get()[i0] = 0;
61  fId_.get()[i0] = 0;
62  fCharge_.get()[i0] = 0;
63  fDZ_.get()[i0] = 0;
64  fDX_.get()[i0] = 0;
65  fDY_.get()[i0] = 0;
66  }
67  auto iParts = iJet.constituents();
68  std::sort(iParts.begin(), iParts.end(), [](edm::Ptr<l1t::PFCandidate> i, edm::Ptr<l1t::PFCandidate> j) {
69  return (i->pt() > j->pt());
70  });
71  float jetpt = useRawPt ? iJet.rawPt() : iJet.pt();
72  for (unsigned int i0 = 0; i0 < iParts.size(); i0++) {
73  if (i0 >= (unsigned int)fNParticles_)
74  break;
75  fPt_.get()[i0] = iParts[i0]->pt() / jetpt;
76  fEta_.get()[i0] = iParts[i0]->eta() - iJet.eta();
77  fPhi_.get()[i0] = deltaPhi(iParts[i0]->phi(), iJet.phi());
78  fId_.get()[i0] = iParts[i0]->id();
79  fCharge_.get()[i0] = iParts[i0]->charge();
80  if (iParts[i0]->pfTrack().isNonnull()) {
81  fDX_.get()[i0] = iParts[i0]->pfTrack()->vx();
82  fDY_.get()[i0] = iParts[i0]->pfTrack()->vy();
83  fDZ_.get()[i0] = iParts[i0]->pfTrack()->vz() - vz;
84  }
85  }
87  return EvaluateNN();
88 }
void setNNVectorVar()
Definition: BJetId.cc:23
int fNParticles_
Definition: BJetId.h:31
double pt() const final
transverse momentum
float EvaluateNN()
Definition: BJetId.cc:46
unique_ptr< float[]> fPhi_
Definition: BJetId.h:34
unique_ptr< int[]> fCharge_
Definition: BJetId.h:36
unique_ptr< float[]> fId_
Definition: BJetId.h:35
unique_ptr< float[]> fDX_
Definition: BJetId.h:38
float rawPt() const
Definition: PFJet.h:27
unique_ptr< float[]> fDZ_
Definition: BJetId.h:37
const Constituents & constituents() const
constituent information. note that this is not going to be available in the hardware! ...
Definition: PFJet.h:30
unique_ptr< float[]> fDY_
Definition: BJetId.h:39
unique_ptr< float[]> fEta_
Definition: BJetId.h:33
unique_ptr< float[]> fPt_
Definition: BJetId.h:32
double phi() const final
momentum azimuthal angle
double eta() const final
momentum pseudorapidity

◆ EvaluateNN()

float BJetId::EvaluateNN ( )

Definition at line 46 of file BJetId.cc.

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

Referenced by compute().

46  {
47  tensorflow::Tensor input(tensorflow::DT_FLOAT, {1, (unsigned int)NNvectorVar_.size(), 1});
48  for (unsigned int i = 0; i < NNvectorVar_.size(); i++) {
49  input.tensor<float, 3>()(0, i, 0) = float(NNvectorVar_[i]);
50  }
51  std::vector<tensorflow::Tensor> outputs;
53  return outputs[0].matrix<float>()(0, 0);
54 } //end EvaluateNN
tensorflow::Session * sessionRef_
Definition: BJetId.h:40
std::string fOutput_
Definition: BJetId.h:30
std::string fInput_
Definition: BJetId.h:29
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:281
std::vector< float > NNvectorVar_
Definition: BJetId.h:28

◆ setNNVectorVar()

void BJetId::setNNVectorVar ( )

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

23  {
24  NNvectorVar_.clear();
25  for (int i0 = 0; i0 < fNParticles_; i0++) {
26  if (fPt_.get()[i0] == 0) {
27  for (int i1 = 0; i1 < 13; i1++)
28  NNvectorVar_.push_back(0);
29  continue;
30  }
31  NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Electron && fCharge_.get()[i0] < 0); // Electron
32  NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Electron && fCharge_.get()[i0] > 0); // Positron
33  NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Muon && fCharge_.get()[i0] < 0); // Muon
34  NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Muon && fCharge_.get()[i0] > 0); // Anti-Muon
35  NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::Photon); // Photon
36  NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::NeutralHadron); // Neutral Had
37  NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::ChargedHadron && fCharge_.get()[i0] < 0); // Pion
38  NNvectorVar_.push_back(fId_.get()[i0] == l1t::PFCandidate::ChargedHadron && fCharge_.get()[i0] > 0); // Anti-Pion
39  NNvectorVar_.push_back(fDZ_.get()[i0]); //dZ
40  NNvectorVar_.push_back(std::hypot(fDX_.get()[i0], fDY_.get()[i0])); //d0
41  NNvectorVar_.push_back(fPt_.get()[i0]); //pT as a fraction of jet pT
42  NNvectorVar_.push_back(fEta_.get()[i0]); //dEta from jet axis
43  NNvectorVar_.push_back(fPhi_.get()[i0]); //dPhi from jet axis
44  }
45 }
MPlex< T, D1, D2, N > hypot(const MPlex< T, D1, D2, N > &a, const MPlex< T, D1, D2, N > &b)
Definition: Matriplex.h:436
int fNParticles_
Definition: BJetId.h:31
unique_ptr< float[]> fPhi_
Definition: BJetId.h:34
unique_ptr< int[]> fCharge_
Definition: BJetId.h:36
unique_ptr< float[]> fId_
Definition: BJetId.h:35
unique_ptr< float[]> fDX_
Definition: BJetId.h:38
unique_ptr< float[]> fDZ_
Definition: BJetId.h:37
unique_ptr< float[]> fDY_
Definition: BJetId.h:39
unique_ptr< float[]> fEta_
Definition: BJetId.h:33
unique_ptr< float[]> fPt_
Definition: BJetId.h:32
std::vector< float > NNvectorVar_
Definition: BJetId.h:28

Member Data Documentation

◆ fCharge_

unique_ptr<int[]> BJetId::fCharge_
private

Definition at line 36 of file BJetId.h.

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

◆ fDX_

unique_ptr<float[]> BJetId::fDX_
private

Definition at line 38 of file BJetId.h.

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

◆ fDY_

unique_ptr<float[]> BJetId::fDY_
private

Definition at line 39 of file BJetId.h.

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

◆ fDZ_

unique_ptr<float[]> BJetId::fDZ_
private

Definition at line 37 of file BJetId.h.

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

◆ fEta_

unique_ptr<float[]> BJetId::fEta_
private

Definition at line 33 of file BJetId.h.

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

◆ fId_

unique_ptr<float[]> BJetId::fId_
private

Definition at line 35 of file BJetId.h.

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

◆ fInput_

std::string BJetId::fInput_
private

Definition at line 29 of file BJetId.h.

Referenced by BJetId(), and EvaluateNN().

◆ fNParticles_

int BJetId::fNParticles_
private

Definition at line 31 of file BJetId.h.

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

◆ fOutput_

std::string BJetId::fOutput_
private

Definition at line 30 of file BJetId.h.

Referenced by BJetId(), and EvaluateNN().

◆ fPhi_

unique_ptr<float[]> BJetId::fPhi_
private

Definition at line 34 of file BJetId.h.

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

◆ fPt_

unique_ptr<float[]> BJetId::fPt_
private

Definition at line 32 of file BJetId.h.

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

◆ NNvectorVar_

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

Definition at line 28 of file BJetId.h.

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

◆ sessionRef_

tensorflow::Session* BJetId::sessionRef_
private

Definition at line 40 of file BJetId.h.

Referenced by EvaluateNN().