CMS 3D CMS Logo

tensor_fillers.h
Go to the documentation of this file.
1 #ifndef RecoBTag_ONNXRuntime_tensor_fillers_h
2 #define RecoBTag_ONNXRuntime_tensor_fillers_h
3 
8 
9 namespace btagbtvdeep {
10 
12 
13  void cpf_tensor_filler(float*& ptr, const btagbtvdeep::ChargedCandidateFeatures& c_pf_features);
14 
15  void npf_tensor_filler(float*& ptr, const btagbtvdeep::NeutralCandidateFeatures& n_pf_features);
16 
17  void sv_tensor_filler(float*& ptr, const btagbtvdeep::SecondaryVertexFeatures& sv_features);
18 
19  void jet4vec_tensor_filler(float*& ptr, const btagbtvdeep::JetFeatures& jet_features);
20 
21  void seedTrack_tensor_filler(float*& ptr, const btagbtvdeep::SeedingTrackFeatures& seed_features);
22 
23  void neighbourTrack_tensor_filler(float*& ptr, const btagbtvdeep::TrackPairFeatures& neighbourTrack_features);
24 
25  std::vector<float> inputs_parT(const btagbtvdeep::ChargedCandidateFeatures& c_pf_features,
26  parT::InputFeatures ifeature);
27 
28  std::vector<float> inputs_parT(const btagbtvdeep::NeutralCandidateFeatures& n_pf_features,
29  parT::InputFeatures ifeature);
30 
31  std::vector<float> inputs_parT(const btagbtvdeep::SecondaryVertexFeatures& sv_features, parT::InputFeatures ifeature);
32 
33  template <class parT_features>
35  const parT::InputFeatures ifeature,
36  const std::vector<parT_features>& features,
37  const unsigned int max_n,
38  const float*& start,
39  unsigned offset) {
40  float* ptr = nullptr;
41  for (std::size_t n = 0; n < max_n; n++) {
42  const auto& f = features.at(n);
43  ptr = &data[ifeature][offset + n * parT::N_InputFeatures.at(ifeature)];
44  start = ptr;
45  const std::vector<float>& inputs = inputs_parT(f, ifeature);
46  for (unsigned int i = 0; i < inputs.size(); i++) {
47  *ptr = inputs[i];
48  ++ptr;
49  }
50  if (inputs.size() > 0)
51  --ptr;
52  assert(start + parT::N_InputFeatures.at(ifeature) - 1 == ptr);
53  }
54  }
55 
56  template <class parT_features>
57  void parT_tensor_filler(std::vector<float>& vdata,
58  const parT::InputFeatures ifeature,
59  const std::vector<parT_features>& features,
60  const unsigned int target_n) {
61  unsigned int n =
62  std::clamp((unsigned int)features.size(), (unsigned int)0, (unsigned int)parT::N_AcceptedFeatures.at(ifeature));
63  for (unsigned int count = 0; count < n; count++) {
64  const std::vector<float>& inputs = inputs_parT(features.at(count), ifeature);
65  vdata.insert(vdata.end(), inputs.begin(), inputs.end());
66  }
67  unsigned int n_features = parT::N_InputFeatures.at(ifeature);
68  if (n < target_n)
69  vdata.insert(vdata.end(), (target_n - n) * n_features, 0); // Add 0 to unfilled part as padding value
70  }
71 
72 } // namespace btagbtvdeep
73 
74 #endif
Definition: start.py:1
void npf_tensor_filler(float *&ptr, const btagbtvdeep::NeutralCandidateFeatures &n_pf_features)
constexpr std::array< unsigned int, kEnd > N_AcceptedFeatures
void cpf_tensor_filler(float *&ptr, const btagbtvdeep::ChargedCandidateFeatures &c_pf_features)
constexpr std::array< unsigned int, kEnd > N_InputFeatures
std::vector< std::vector< float > > FloatArrays
Definition: ONNXRuntime.h:23
assert(be >=bs)
void sv_tensor_filler(float *&ptr, const btagbtvdeep::SecondaryVertexFeatures &sv_features)
std::vector< float > features(const reco::PreId &ecal, const reco::PreId &hcal, double rho, const reco::BeamSpot &spot, noZS::EcalClusterLazyTools &ecalTools)
double f[11][100]
void neighbourTrack_tensor_filler(float *&ptr, const btagbtvdeep::TrackPairFeatures &neighbourTrack_features)
void jet_tensor_filler(float *&ptr, const btagbtvdeep::DeepFlavourFeatures &features)
void parT_tensor_filler(cms::Ort::FloatArrays &data, const parT::InputFeatures ifeature, const std::vector< parT_features > &features, const unsigned int max_n, const float *&start, unsigned offset)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
void seedTrack_tensor_filler(float *&ptr, const btagbtvdeep::SeedingTrackFeatures &seed_features)
std::vector< float > inputs_parT(const btagbtvdeep::ChargedCandidateFeatures &c_pf_features, parT::InputFeatures ifeature)
void jet4vec_tensor_filler(float *&ptr, const btagbtvdeep::JetFeatures &jet_features)