|
3 | 3 |
|
4 | 4 | #include "DataFormats/BTauReco/interface/DeepFlavourTagInfo.h" |
5 | 5 | #include "DataFormats/BTauReco/interface/ParticleTransformerAK4Features.h" |
| 6 | +#include "DataFormats/BTauReco/interface/UnifiedParticleTransformerAK4Features.h" |
6 | 7 | #include "PhysicsTools/ONNXRuntime/interface/ONNXRuntime.h" |
7 | 8 | #include "RecoBTag/ONNXRuntime/interface/tensor_configs.h" |
8 | 9 |
|
@@ -30,6 +31,17 @@ namespace btagbtvdeep { |
30 | 31 |
|
31 | 32 | std::vector<float> inputs_parT(const btagbtvdeep::SecondaryVertexFeatures& sv_features, parT::InputFeatures ifeature); |
32 | 33 |
|
| 34 | + std::vector<float> inputs_UparT(const btagbtvdeep::ChargedCandidateFeatures& c_pf_features, |
| 35 | + UparT::InputFeatures ifeature); |
| 36 | + |
| 37 | + std::vector<float> inputs_UparT(const btagbtvdeep::LostTracksFeatures& lt_features, UparT::InputFeatures ifeature); |
| 38 | + |
| 39 | + std::vector<float> inputs_UparT(const btagbtvdeep::NeutralCandidateFeatures& n_pf_features, |
| 40 | + UparT::InputFeatures ifeature); |
| 41 | + |
| 42 | + std::vector<float> inputs_UparT(const btagbtvdeep::SecondaryVertexFeatures& sv_features, |
| 43 | + UparT::InputFeatures ifeature); |
| 44 | + |
33 | 45 | template <class parT_features> |
34 | 46 | void parT_tensor_filler(cms::Ort::FloatArrays& data, |
35 | 47 | const parT::InputFeatures ifeature, |
@@ -69,6 +81,44 @@ namespace btagbtvdeep { |
69 | 81 | vdata.insert(vdata.end(), (target_n - n) * n_features, 0); // Add 0 to unfilled part as padding value |
70 | 82 | } |
71 | 83 |
|
| 84 | + template <class UparT_features> |
| 85 | + void UparT_tensor_filler(cms::Ort::FloatArrays& data, |
| 86 | + const UparT::InputFeatures ifeature, |
| 87 | + const std::vector<UparT_features>& features, |
| 88 | + const unsigned int max_n, |
| 89 | + const float*& start, |
| 90 | + unsigned offset) { |
| 91 | + float* ptr = nullptr; |
| 92 | + for (std::size_t n = 0; n < max_n; n++) { |
| 93 | + const auto& f = features.at(n); |
| 94 | + ptr = &data[ifeature][offset + n * UparT::N_InputFeatures.at(ifeature)]; |
| 95 | + start = ptr; |
| 96 | + const std::vector<float>& inputs = inputs_UparT(f, ifeature); |
| 97 | + for (unsigned int i = 0; i < inputs.size(); i++) { |
| 98 | + *ptr = inputs[i]; |
| 99 | + ++ptr; |
| 100 | + } |
| 101 | + if (inputs.size() > 0) |
| 102 | + --ptr; |
| 103 | + assert(start + UparT::N_InputFeatures.at(ifeature) - 1 == ptr); |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | + template <class UparT_features> |
| 108 | + void UparT_tensor_filler(std::vector<float>& vdata, |
| 109 | + const UparT::InputFeatures ifeature, |
| 110 | + const std::vector<UparT_features>& features, |
| 111 | + const unsigned int target_n) { |
| 112 | + unsigned int n = std::clamp( |
| 113 | + (unsigned int)features.size(), (unsigned int)0, (unsigned int)UparT::N_AcceptedFeatures.at(ifeature)); |
| 114 | + for (unsigned int count = 0; count < n; count++) { |
| 115 | + const std::vector<float>& inputs = inputs_UparT(features.at(count), ifeature); |
| 116 | + vdata.insert(vdata.end(), inputs.begin(), inputs.end()); |
| 117 | + } |
| 118 | + unsigned int n_features = UparT::N_InputFeatures.at(ifeature); |
| 119 | + if (n < target_n) |
| 120 | + vdata.insert(vdata.end(), (target_n - n) * n_features, 0); // Add 0 to unfilled part as padding value |
| 121 | + } |
72 | 122 | } // namespace btagbtvdeep |
73 | 123 |
|
74 | 124 | #endif |
0 commit comments