CMS 3D CMS Logo

DeepBoostedJetFeatures.h
Go to the documentation of this file.
1 #ifndef DataFormats_BTauReco_DeepBoostedJetFeatures_h
2 #define DataFormats_BTauReco_DeepBoostedJetFeatures_h
3 
4 #include <string>
5 #include <vector>
6 #include <unordered_map>
8 
9 namespace btagbtvdeep {
10 
12  public:
13  bool empty() const { return is_empty_; }
14 
15  void add(const std::string& name) { feature_map_[name]; }
16 
17  void reserve(const std::string& name, unsigned capacity) { feature_map_[name].reserve(capacity); }
18 
19  void fill(const std::string& name, float value) {
20  auto item = feature_map_.find(name);
21  if (item != feature_map_.end()) {
22  item->second.push_back(value);
23  is_empty_ = false;
24  } else {
25  throw cms::Exception("InvalidArgument")
26  << "[DeepBoostedJetFeatures::fill()] Feature " << name << " has not been registered";
27  }
28  }
29 
30  void set(const std::string& name, const std::vector<float>& vec) { feature_map_[name] = vec; }
31 
32  void check_consistency(const std::vector<std::string>& names) const {
33  if (names.empty())
34  return;
35  const auto ref_len = get(names.front()).size();
36  for (unsigned i = 1; i < names.size(); ++i) {
37  if (get(names[i]).size() != ref_len) {
38  throw cms::Exception("InvalidArgument")
39  << "[DeepBoostedJetFeatures::check_consistency()] Inconsistent variable length " << get(names[i]).size()
40  << " for " << names[i] << ", should be " << ref_len;
41  }
42  }
43  }
44 
45  const std::vector<float>& get(const std::string& name) const {
46  auto item = feature_map_.find(name);
47  if (item != feature_map_.end()) {
48  return item->second;
49  } else {
50  throw cms::Exception("InvalidArgument")
51  << "[DeepBoostedJetFeatures::get()] Feature " << name << " does not exist!";
52  }
53  }
54 
55  private:
56  bool is_empty_ = true;
57  std::unordered_map<std::string, std::vector<float>> feature_map_;
58  };
59 
60 } // namespace btagbtvdeep
61 
62 #endif // DataFormats_BTauReco_DeepBoostedJetFeatures_h
size
Write out results.
const std::string names[nVars_]
void reserve(const std::string &name, unsigned capacity)
void check_consistency(const std::vector< std::string > &names) const
Definition: value.py:1
std::unordered_map< std::string, std::vector< float > > feature_map_
void add(const std::string &name)
void fill(const std::string &name, float value)
size d for d tracks hist hist capacity()