CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes
DeepVertexONNXJetTagsProducer Class Reference
Inheritance diagram for DeepVertexONNXJetTagsProducer:
edm::stream::EDProducer< edm::GlobalCache< ONNXRuntime > >

Public Member Functions

 DeepVertexONNXJetTagsProducer (const edm::ParameterSet &, const ONNXRuntime *)
 
 ~DeepVertexONNXJetTagsProducer () override
 
- Public Member Functions inherited from edm::stream::EDProducer< edm::GlobalCache< ONNXRuntime > >
 EDProducer ()=default
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &)
 
static void globalEndJob (const ONNXRuntime *)
 
static std::unique_ptr< ONNXRuntimeinitializeGlobalCache (const edm::ParameterSet &)
 

Private Types

enum  InputIndexes { kGlobal = 0, kSeedingTracks = 1, kNeighbourTracks = 2 }
 
typedef reco::JetTagCollection JetTagCollection
 
typedef std::vector< reco::DeepFlavourTagInfoTagInfoCollection
 

Private Member Functions

void make_inputs (unsigned i_jet, const reco::DeepFlavourTagInfo &taginfo)
 
void produce (edm::Event &, const edm::EventSetup &) override
 

Private Attributes

FloatArrays data_
 
std::vector< std::string > flav_names_
 
std::vector< std::string > input_names_
 
const double max_jet_eta_
 
const double min_jet_pt_
 
std::vector< std::string > output_names_
 
const edm::EDGetTokenT< TagInfoCollectionsrc_
 

Static Private Attributes

static const std::vector< unsigned > input_sizes_
 
static const unsigned n_features_global_ = deepvertex::n_features_global
 
static const unsigned n_features_neighbor_ = deepvertex::n_features_neighbor
 
static const unsigned n_features_seed_ = deepvertex::n_features_seed
 
static const unsigned n_neighbor_ = deepvertex::n_neighbor
 
static const unsigned n_seed_ = deepvertex::n_seed
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer< edm::GlobalCache< ONNXRuntime > >
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 

Detailed Description

Definition at line 23 of file DeepVertexONNXJetTagsProducer.cc.

Member Typedef Documentation

Definition at line 35 of file DeepVertexONNXJetTagsProducer.cc.

Definition at line 34 of file DeepVertexONNXJetTagsProducer.cc.

Member Enumeration Documentation

Constructor & Destructor Documentation

DeepVertexONNXJetTagsProducer::DeepVertexONNXJetTagsProducer ( const edm::ParameterSet iConfig,
const ONNXRuntime cache 
)
explicit

Definition at line 75 of file DeepVertexONNXJetTagsProducer.cc.

References flav_names_, input_names_, and input_sizes_.

76  : src_(consumes<TagInfoCollection>(iConfig.getParameter<edm::InputTag>("src"))),
77  flav_names_(iConfig.getParameter<std::vector<std::string>>("flav_names")),
78  input_names_(iConfig.getParameter<std::vector<std::string>>("input_names")),
79  output_names_(iConfig.getParameter<std::vector<std::string>>("output_names")),
80  min_jet_pt_(iConfig.getParameter<double>("min_jet_pt")),
81  max_jet_eta_(iConfig.getParameter<double>("max_jet_eta")) {
82  // get output names from flav_names
83  for (const auto& flav_name : flav_names_) {
84  produces<JetTagCollection>(flav_name);
85  }
86 
87  assert(input_names_.size() == input_sizes_.size());
88 }
T getParameter(std::string const &) const
const edm::EDGetTokenT< TagInfoCollection > src_
static const std::vector< unsigned > input_sizes_
DeepVertexONNXJetTagsProducer::~DeepVertexONNXJetTagsProducer ( )
override

Definition at line 90 of file DeepVertexONNXJetTagsProducer.cc.

90 {}

Member Function Documentation

void DeepVertexONNXJetTagsProducer::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 92 of file DeepVertexONNXJetTagsProducer.cc.

References edm::ConfigurationDescriptions::add(), and edm::ParameterSetDescription::add().

92  {
93  // pfDeepFlavourJetTags
95  desc.add<edm::InputTag>("src", edm::InputTag("pfDeepFlavourTagInfos"));
96  desc.add<std::vector<std::string>>("input_names",
97  {"input_1",
98  "input_2",
99  "input_3",
100  "input_4",
101  "input_5",
102  "input_6",
103  "input_7",
104  "input_8",
105  "input_9",
106  "input_10",
107  "input_11",
108  "input_12"});
109  desc.add<edm::FileInPath>("model_path", edm::FileInPath("RecoBTag/Combined/data/DeepVertex/phase1_deepvertex.onnx"));
110  desc.add<std::vector<std::string>>("output_names", {"dense_6"});
111  desc.add<std::vector<std::string>>("flav_names", std::vector<std::string>{"probb", "probc", "probuds", "probg"});
112  desc.add<double>("min_jet_pt", 15.0);
113  desc.add<double>("max_jet_eta", 2.5);
114 
115  descriptions.add("pfDeepVertexJetTags", desc);
116 }
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void DeepVertexONNXJetTagsProducer::globalEndJob ( const ONNXRuntime cache)
static

Definition at line 122 of file DeepVertexONNXJetTagsProducer.cc.

122 {}
std::unique_ptr< ONNXRuntime > DeepVertexONNXJetTagsProducer::initializeGlobalCache ( const edm::ParameterSet iConfig)
static

Definition at line 118 of file DeepVertexONNXJetTagsProducer.cc.

References edm::ParameterSet::getParameter().

118  {
119  return std::make_unique<ONNXRuntime>(iConfig.getParameter<edm::FileInPath>("model_path").fullPath());
120 }
T getParameter(std::string const &) const
void DeepVertexONNXJetTagsProducer::make_inputs ( unsigned  i_jet,
const reco::DeepFlavourTagInfo taginfo 
)
private

Definition at line 195 of file DeepVertexONNXJetTagsProducer.cc.

References data_, DEFINE_FWK_MODULE, postprocess-scan-build::features, reco::FeaturesTagInfo< Features >::features(), input_sizes_, btagbtvdeep::jet4vec_tensor_filler(), kGlobal, kNeighbourTracks, kSeedingTracks, min(), n_features_global_, n_features_neighbor_, n_features_seed_, n_neighbor_, n_seed_, btagbtvdeep::neighbourTrack_tensor_filler(), PFRecoTauDiscriminationByIsolation_cfi::offset, and btagbtvdeep::seedTrack_tensor_filler().

Referenced by produce().

195  {
196  const auto& features = taginfo.features();
197  float* ptr = nullptr;
198  const float* start = nullptr;
199  unsigned offset = 0;
200 
201  // jet variables
202  offset = i_jet * input_sizes_[kGlobal];
203  const auto& jet_features = features.jet_features;
204  ptr = &data_[kGlobal][offset];
205  start = ptr;
206  jet4vec_tensor_filler(ptr, jet_features);
207  assert(start + n_features_global_ - 1 == ptr);
208 
209  // seeds
210  auto max_seed_n = std::min(features.seed_features.size(), (std::size_t)n_seed_);
211  offset = i_jet * input_sizes_[kSeedingTracks];
212  for (std::size_t seed_n = 0; seed_n < max_seed_n; seed_n++) {
213  const auto& seed_features = features.seed_features[seed_n];
214  ptr = &data_[kSeedingTracks][offset + seed_n * n_features_seed_];
215  start = ptr;
216  seedTrack_tensor_filler(ptr, seed_features);
217  assert(start + n_features_seed_ - 1 == ptr);
218  }
219 
220  // neighbours
221  offset = i_jet * input_sizes_[kNeighbourTracks];
222  for (std::size_t seed_n = 0; seed_n < max_seed_n; seed_n++) {
223  const auto& neighbourTracks_features = features.seed_features[seed_n].nearTracks;
224  auto max_neighbour_n = std::min(neighbourTracks_features.size(), (std::size_t)n_neighbor_);
225  for (std::size_t neighbour_n = 0; neighbour_n < max_neighbour_n; neighbour_n++) {
226  ptr = &data_[kNeighbourTracks + seed_n][offset + neighbour_n * n_features_neighbor_];
227  start = ptr;
228  neighbourTrack_tensor_filler(ptr, neighbourTracks_features[neighbour_n]);
229  assert(start + n_features_neighbor_ - 1 == ptr);
230  }
231  }
232 }
const Features & features() const
Definition: start.py:1
static const std::vector< unsigned > input_sizes_
void neighbourTrack_tensor_filler(float *&ptr, const btagbtvdeep::TrackPairFeatures &neighbourTrack_features)
T min(T a, T b)
Definition: MathUtil.h:58
void seedTrack_tensor_filler(float *&ptr, const btagbtvdeep::SeedingTrackFeatures &seed_features)
void jet4vec_tensor_filler(float *&ptr, const btagbtvdeep::JetFeatures &jet_features)
void DeepVertexONNXJetTagsProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 124 of file DeepVertexONNXJetTagsProducer.cc.

References data_, flav_names_, edm::Event::getByToken(), mps_fire::i, input_names_, input_sizes_, make_inputs(), edm::makeRefToBaseProdFrom(), max_jet_eta_, min_jet_pt_, eostools::move(), output_names_, PatBasicFWLiteJetAnalyzer_Selector_cfg::outputs, edm::Event::put(), src_, and lumiTag::taginfo.

124  {
126  iEvent.getByToken(src_, tag_infos);
127 
128  data_.clear();
129 
130  std::vector<std::unique_ptr<JetTagCollection>> output_tags;
131  if (!tag_infos->empty()) {
132  unsigned good_taginfo_count = 0;
133  std::vector<bool> good_taginfo_jets(tag_infos->size(), false);
134  for (unsigned jet_n = 0; jet_n < tag_infos->size(); ++jet_n) {
135  const auto& jet_ref = (*tag_infos)[jet_n].jet();
136  if (jet_ref->pt() > min_jet_pt_ && std::fabs(jet_ref->eta()) < max_jet_eta_) {
137  good_taginfo_count++;
138  good_taginfo_jets[jet_n] = true;
139  }
140  }
141 
142  // init data storage w correct size
143  for (const auto& len : input_sizes_) {
144  data_.emplace_back(good_taginfo_count * len, 0);
145  }
146 
147  // initialize output collection
148  auto jet_ref = tag_infos->begin()->jet();
149  auto ref2prod = edm::makeRefToBaseProdFrom(jet_ref, iEvent);
150  for (std::size_t i = 0; i < flav_names_.size(); i++) {
151  output_tags.emplace_back(std::make_unique<JetTagCollection>(ref2prod));
152  }
153 
154  // convert inputs
155  unsigned inputs_done_count = 0;
156  for (unsigned jet_n = 0; jet_n < tag_infos->size(); ++jet_n) {
157  if (good_taginfo_jets[jet_n]) {
158  const auto& taginfo = (*tag_infos)[jet_n];
159  make_inputs(inputs_done_count, taginfo);
160  inputs_done_count++;
161  }
162  }
163 
164  // run prediction
165  assert(inputs_done_count == good_taginfo_count);
166  const auto outputs = globalCache()->run(input_names_, data_, {}, output_names_, good_taginfo_count)[0];
167  assert(outputs.size() == flav_names_.size() * good_taginfo_count);
168 
169  // get the outputs
170  unsigned i_output = 0;
171  for (unsigned jet_n = 0; jet_n < tag_infos->size(); ++jet_n) {
172  const auto& jet_ref = (*tag_infos)[jet_n].jet();
173  for (std::size_t flav_n = 0; flav_n < flav_names_.size(); flav_n++) {
174  if (good_taginfo_jets[jet_n]) {
175  (*(output_tags[flav_n]))[jet_ref] = outputs[i_output];
176  ++i_output;
177  } else {
178  (*(output_tags[flav_n]))[jet_ref] = -2;
179  }
180  }
181  }
182  } else {
183  // create empty output collection
184  for (std::size_t i = 0; i < flav_names_.size(); i++) {
185  output_tags.emplace_back(std::make_unique<JetTagCollection>());
186  }
187  }
188 
189  // put into the event
190  for (std::size_t flav_n = 0; flav_n < flav_names_.size(); ++flav_n) {
191  iEvent.put(std::move(output_tags[flav_n]), flav_names_[flav_n]);
192  }
193 }
const edm::EDGetTokenT< TagInfoCollection > src_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
taginfo
Definition: lumiTag.py:81
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
static const std::vector< unsigned > input_sizes_
void make_inputs(unsigned i_jet, const reco::DeepFlavourTagInfo &taginfo)
RefToBaseProd< T > makeRefToBaseProdFrom(RefToBase< T > const &iRef, Event const &iEvent)
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

FloatArrays DeepVertexONNXJetTagsProducer::data_
private

Definition at line 59 of file DeepVertexONNXJetTagsProducer.cc.

Referenced by make_inputs(), and produce().

std::vector<std::string> DeepVertexONNXJetTagsProducer::flav_names_
private

Definition at line 42 of file DeepVertexONNXJetTagsProducer.cc.

Referenced by DeepVertexONNXJetTagsProducer(), and produce().

std::vector<std::string> DeepVertexONNXJetTagsProducer::input_names_
private

Definition at line 43 of file DeepVertexONNXJetTagsProducer.cc.

Referenced by DeepVertexONNXJetTagsProducer(), and produce().

const std::vector< unsigned > DeepVertexONNXJetTagsProducer::input_sizes_
staticprivate
const double DeepVertexONNXJetTagsProducer::max_jet_eta_
private

Definition at line 47 of file DeepVertexONNXJetTagsProducer.cc.

Referenced by produce().

const double DeepVertexONNXJetTagsProducer::min_jet_pt_
private

Definition at line 46 of file DeepVertexONNXJetTagsProducer.cc.

Referenced by produce().

const unsigned DeepVertexONNXJetTagsProducer::n_features_global_ = deepvertex::n_features_global
staticprivate

Definition at line 50 of file DeepVertexONNXJetTagsProducer.cc.

Referenced by make_inputs().

const unsigned DeepVertexONNXJetTagsProducer::n_features_neighbor_ = deepvertex::n_features_neighbor
staticprivate

Definition at line 54 of file DeepVertexONNXJetTagsProducer.cc.

Referenced by make_inputs().

const unsigned DeepVertexONNXJetTagsProducer::n_features_seed_ = deepvertex::n_features_seed
staticprivate

Definition at line 52 of file DeepVertexONNXJetTagsProducer.cc.

Referenced by make_inputs().

const unsigned DeepVertexONNXJetTagsProducer::n_neighbor_ = deepvertex::n_neighbor
staticprivate

Definition at line 53 of file DeepVertexONNXJetTagsProducer.cc.

Referenced by make_inputs().

const unsigned DeepVertexONNXJetTagsProducer::n_seed_ = deepvertex::n_seed
staticprivate

Definition at line 51 of file DeepVertexONNXJetTagsProducer.cc.

Referenced by make_inputs().

std::vector<std::string> DeepVertexONNXJetTagsProducer::output_names_
private

Definition at line 44 of file DeepVertexONNXJetTagsProducer.cc.

Referenced by produce().

const edm::EDGetTokenT<TagInfoCollection> DeepVertexONNXJetTagsProducer::src_
private

Definition at line 41 of file DeepVertexONNXJetTagsProducer.cc.

Referenced by produce().