-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ParT and UParT SONIC producer second pull request #17
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import FWCore.ParameterSet.Config as cms | ||
|
||
particleTransformerAK4SonicTriton = cms.Modifier() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import FWCore.ParameterSet.Config as cms | ||
|
||
unifiedparticleTransformerAK4SonicTriton = cms.Modifier() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
<use name="PhysicsTools/ONNXRuntime"/> | ||
<use name="DataFormats/BTauReco"/> | ||
<export> | ||
<lib name="1"/> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
#ifndef RecoBTag_ONNXRuntime_tensor_configs_h | ||
#define RecoBTag_ONNXRuntime_tensor_configs_h | ||
|
||
#include <map> | ||
|
||
namespace deepflavour { | ||
|
||
constexpr unsigned n_features_global = 15; | ||
|
@@ -28,4 +30,85 @@ namespace deepvertex { | |
|
||
} // namespace deepvertex | ||
|
||
namespace parT { | ||
|
||
enum InputFeatures { | ||
kBegin=0, | ||
kChargedCandidates=kBegin, | ||
kNeutralCandidates=1, | ||
kVertices=2, | ||
kChargedCandidates4Vec=3, | ||
kNeutralCandidates4Vec=4, | ||
kVertices4Vec=5, | ||
kEnd=6 | ||
}; | ||
|
||
constexpr unsigned n_cpf_accept = 25; | ||
constexpr unsigned n_npf_accept = 25; | ||
constexpr unsigned n_sv_accept = 5; | ||
|
||
const std::map<InputFeatures, unsigned int> N_InputFeatures{ | ||
{kChargedCandidates, 16}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these could actually be vectors rather than maps, since the enum is ordered and dense. that would speed up some of the operations in the producers. |
||
{kNeutralCandidates, 8}, | ||
{kVertices, 14}, | ||
{kChargedCandidates4Vec, 4}, | ||
{kNeutralCandidates4Vec, 4}, | ||
{kVertices4Vec, 4} | ||
}; | ||
|
||
const std::map<InputFeatures, unsigned int> N_AcceptedFeatures{ | ||
{kChargedCandidates, n_cpf_accept}, | ||
{kNeutralCandidates, n_npf_accept}, | ||
{kVertices, n_sv_accept}, | ||
{kChargedCandidates4Vec, n_cpf_accept}, | ||
{kNeutralCandidates4Vec, n_npf_accept}, | ||
{kVertices4Vec, n_sv_accept} | ||
}; | ||
|
||
} // namespace parT | ||
|
||
|
||
namespace UparT { | ||
|
||
enum InputFeatures { | ||
kBegin=0, | ||
kChargedCandidates=kBegin, | ||
kLostTracks = 1, | ||
kNeutralCandidates=2, | ||
kVertices=3, | ||
kChargedCandidates4Vec=4, | ||
kLostTracks4Vec=5, | ||
kNeutralCandidates4Vec=6, | ||
kVertices4Vec=7, | ||
kEnd=8 | ||
}; | ||
|
||
constexpr unsigned n_cpf_accept = 29; | ||
constexpr unsigned n_lt_accept = 5; | ||
constexpr unsigned n_npf_accept = 25; | ||
constexpr unsigned n_sv_accept = 5; | ||
|
||
const std::map<InputFeatures, unsigned int> N_InputFeatures{ | ||
{kChargedCandidates, 25}, | ||
{kLostTracks, 18}, | ||
{kNeutralCandidates, 8}, | ||
{kVertices, 14}, | ||
{kChargedCandidates4Vec, 4}, | ||
{kLostTracks4Vec, 4}, | ||
{kNeutralCandidates4Vec, 4}, | ||
{kVertices4Vec, 4} | ||
}; | ||
|
||
const std::map<InputFeatures, unsigned int> N_AcceptedFeatures{ | ||
{kChargedCandidates, n_cpf_accept}, | ||
{kLostTracks, n_lt_accept}, | ||
{kNeutralCandidates, n_npf_accept}, | ||
{kVertices, n_sv_accept}, | ||
{kChargedCandidates4Vec, n_cpf_accept}, | ||
{kLostTracks4Vec, n_lt_accept}, | ||
{kNeutralCandidates4Vec, n_npf_accept}, | ||
{kVertices4Vec, n_sv_accept} | ||
}; | ||
|
||
} // namespace UparT | ||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,10 @@ | |
#define RecoBTag_ONNXRuntime_tensor_fillers_h | ||
|
||
#include "DataFormats/BTauReco/interface/DeepFlavourTagInfo.h" | ||
#include "DataFormats/BTauReco/interface/ParticleTransformerAK4Features.h" | ||
#include "DataFormats/BTauReco/interface/UnifiedParticleTransformerAK4Features.h" | ||
#include "PhysicsTools/ONNXRuntime/interface/ONNXRuntime.h" | ||
#include "RecoBTag/ONNXRuntime/interface/tensor_configs.h" | ||
|
||
namespace btagbtvdeep { | ||
|
||
|
@@ -19,6 +23,79 @@ namespace btagbtvdeep { | |
|
||
void neighbourTrack_tensor_filler(float*& ptr, const btagbtvdeep::TrackPairFeatures& neighbourTrack_features); | ||
|
||
std::vector<float> inputs_parT(const btagbtvdeep::ChargedCandidateFeatures& c_pf_features, parT::InputFeatures ifeature); | ||
|
||
std::vector<float> inputs_parT(const btagbtvdeep::NeutralCandidateFeatures& n_pf_features, parT::InputFeatures ifeature); | ||
|
||
std::vector<float> inputs_parT(const btagbtvdeep::SecondaryVertexFeatures& sv_features, parT::InputFeatures ifeature); | ||
|
||
std::vector<float> inputs_UparT(const btagbtvdeep::ChargedCandidateFeatures& c_pf_features, UparT::InputFeatures ifeature); | ||
|
||
std::vector<float> inputs_UparT(const btagbtvdeep::LostTracksFeatures& lt_features, UparT::InputFeatures ifeature); | ||
|
||
std::vector<float> inputs_UparT(const btagbtvdeep::NeutralCandidateFeatures& n_pf_features, UparT::InputFeatures ifeature); | ||
|
||
std::vector<float> inputs_UparT(const btagbtvdeep::SecondaryVertexFeatures& sv_features, UparT::InputFeatures ifeature); | ||
|
||
template<class parT_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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make sure to run these commands before submitting the official PR:
|
||
float* ptr = nullptr; | ||
for (std::size_t n = 0; n < max_n; n++) { | ||
const auto& f = features.at(n); | ||
ptr = &data[ifeature][offset + n * parT::N_InputFeatures.at(ifeature)]; | ||
start = ptr; | ||
const std::vector<float>& inputs = inputs_parT(f, ifeature); | ||
for (unsigned int i = 0; i < inputs.size(); i++) { | ||
*ptr = inputs[i]; | ||
++ptr; | ||
} | ||
if (inputs.size() > 0) --ptr; | ||
assert(start + parT::N_InputFeatures.at(ifeature) - 1 == ptr); | ||
} | ||
} | ||
|
||
template<class parT_features> | ||
void parT_tensor_filler(std::vector<float>& vdata, const parT::InputFeatures ifeature, const std::vector<parT_features>& features, const unsigned int target_n) { | ||
unsigned int n = std::clamp((unsigned int)features.size(), (unsigned int)0, (unsigned int)parT::N_AcceptedFeatures.at(ifeature)); | ||
for (unsigned int count = 0; count < n; count++) { | ||
const std::vector<float>& inputs = inputs_parT(features.at(count), ifeature); | ||
vdata.insert(vdata.end(), inputs.begin(), inputs.end()); | ||
} | ||
unsigned int n_features = parT::N_InputFeatures.at(ifeature); | ||
if (n < target_n) | ||
vdata.insert(vdata.end(), (target_n - n) * n_features, 0); // Add 0 to unfilled part as padding value | ||
} | ||
|
||
template<class UparT_features> | ||
void UparT_tensor_filler(cms::Ort::FloatArrays& data, const UparT::InputFeatures ifeature, const std::vector<UparT_features>& features, const unsigned int max_n, const float*& start, unsigned offset) { | ||
float* ptr = nullptr; | ||
for (std::size_t n = 0; n < max_n; n++) { | ||
const auto& f = features.at(n); | ||
ptr = &data[ifeature][offset + n * UparT::N_InputFeatures.at(ifeature)]; | ||
start = ptr; | ||
const std::vector<float>& inputs = inputs_UparT(f, ifeature); | ||
for (unsigned int i = 0; i < inputs.size(); i++) { | ||
*ptr = inputs[i]; | ||
++ptr; | ||
} | ||
if (inputs.size() > 0) --ptr; | ||
assert(start + UparT::N_InputFeatures.at(ifeature) - 1 == ptr); | ||
} | ||
} | ||
|
||
template<class UparT_features> | ||
void UparT_tensor_filler(std::vector<float>& vdata, const UparT::InputFeatures ifeature, const std::vector<UparT_features>& features, const unsigned int target_n) { | ||
unsigned int n = std::clamp((unsigned int)features.size(), (unsigned int)0, (unsigned int)UparT::N_AcceptedFeatures.at(ifeature)); | ||
for (unsigned int count = 0; count < n; count++) { | ||
const std::vector<float>& inputs = inputs_UparT(features.at(count), ifeature); | ||
vdata.insert(vdata.end(), inputs.begin(), inputs.end()); | ||
} | ||
unsigned int n_features = UparT::N_InputFeatures.at(ifeature); | ||
if (n < target_n) | ||
vdata.insert(vdata.end(), (target_n - n) * n_features, 0); // Add 0 to unfilled part as padding value | ||
} | ||
|
||
|
||
} // namespace btagbtvdeep | ||
|
||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be
nInputFeatures
to follow the CMS naming rules: http://cms-sw.github.io/cms_coding_rules.html#2--naming-rules-1(similarly for the other similar variables below)