CMS 3D CMS Logo

BJetId.cc
Go to the documentation of this file.
3 #include <cmath>
4 
5 BJetId::BJetId(const std::string &iInput, const std::string &iOutput, const BJetTFCache *cache, int iNParticles)
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 }
21 
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 }
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
55 
56 float BJetId::compute(const l1t::PFJet &iJet, float vz, bool useRawPt) {
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
float compute(const l1t::PFJet &iJet, float vz, bool useRawPt)
Definition: BJetId.cc:56
int fNParticles_
Definition: BJetId.h:31
double pt() const final
transverse momentum
float EvaluateNN()
Definition: BJetId.cc:46
tensorflow::Session * sessionRef_
Definition: BJetId.h:40
unique_ptr< float[]> fPhi_
Definition: BJetId.h:34
~BJetId()
Definition: BJetId.cc:22
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
static std::string const input
Definition: EdmProvDump.cc:50
unique_ptr< float[]> fDX_
Definition: BJetId.h:38
float rawPt() const
Definition: PFJet.h:27
void run(Session *session, const NamedTensorList &inputs, const std::vector< std::string > &outputNames, std::vector< Tensor > *outputs, const thread::ThreadPoolOptions &threadPoolOptions)
Definition: TensorFlow.cc:259
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
BJetId(const std::string &iInput, const std::string &iOutput, const BJetTFCache *cache, int iNParticles)
Definition: BJetId.cc:5
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
double phi() const final
momentum azimuthal angle
double eta() const final
momentum pseudorapidity