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
btagbtvdeep
Definition: BoostedDoubleSVTagInfoFeatures.h:4
gpuVertexFinder::capacity
size d for d tracks hist hist capacity()
mps_fire.i
i
Definition: mps_fire.py:428
btagbtvdeep::DeepBoostedJetFeatures::set
void set(const std::string &name, const std::vector< float > &vec)
Definition: DeepBoostedJetFeatures.h:30
btagbtvdeep::DeepBoostedJetFeatures::check_consistency
void check_consistency(const std::vector< std::string > &names) const
Definition: DeepBoostedJetFeatures.h:32
btagbtvdeep::DeepBoostedJetFeatures::reserve
void reserve(const std::string &name, unsigned capacity)
Definition: DeepBoostedJetFeatures.h:17
names
const std::string names[nVars_]
Definition: PhotonIDValueMapProducer.cc:124
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
btagbtvdeep::DeepBoostedJetFeatures::empty
bool empty() const
Definition: DeepBoostedJetFeatures.h:13
btagbtvdeep::DeepBoostedJetFeatures
Definition: DeepBoostedJetFeatures.h:11
btagbtvdeep::DeepBoostedJetFeatures::add
void add(const std::string &name)
Definition: DeepBoostedJetFeatures.h:15
btagbtvdeep::DeepBoostedJetFeatures::is_empty_
bool is_empty_
Definition: DeepBoostedJetFeatures.h:56
value
Definition: value.py:1
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
btagbtvdeep::DeepBoostedJetFeatures::get
const std::vector< float > & get(const std::string &name) const
Definition: DeepBoostedJetFeatures.h:45
btagbtvdeep::DeepBoostedJetFeatures::feature_map_
std::unordered_map< std::string, std::vector< float > > feature_map_
Definition: DeepBoostedJetFeatures.h:57
Exception
Definition: hltDiff.cc:245
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
btagbtvdeep::DeepBoostedJetFeatures::fill
void fill(const std::string &name, float value)
Definition: DeepBoostedJetFeatures.h:19
Exception.h
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443