Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:52:51

0001 #ifndef DataFormats_BTauReco_DeepBoostedJetFeatures_h
0002 #define DataFormats_BTauReco_DeepBoostedJetFeatures_h
0003 
0004 #include <string>
0005 #include <vector>
0006 #include <unordered_map>
0007 #include "FWCore/Utilities/interface/Exception.h"
0008 
0009 namespace btagbtvdeep {
0010 
0011   class DeepBoostedJetFeatures {
0012   public:
0013     bool empty() const { return is_empty_; }
0014 
0015     void add(const std::string& name) { feature_map_[name]; }
0016 
0017     void reserve(const std::string& name, unsigned capacity) { feature_map_[name].reserve(capacity); }
0018 
0019     void fill(const std::string& name, float value) {
0020       auto item = feature_map_.find(name);
0021       if (item != feature_map_.end()) {
0022         item->second.push_back(value);
0023         is_empty_ = false;
0024       } else {
0025         throw cms::Exception("InvalidArgument")
0026             << "[DeepBoostedJetFeatures::fill()] Feature " << name << " has not been registered";
0027       }
0028     }
0029 
0030     void set(const std::string& name, const std::vector<float>& vec) { feature_map_[name] = vec; }
0031 
0032     void check_consistency(const std::vector<std::string>& names) const {
0033       if (names.empty())
0034         return;
0035       const auto ref_len = get(names.front()).size();
0036       for (unsigned i = 1; i < names.size(); ++i) {
0037         if (get(names[i]).size() != ref_len) {
0038           throw cms::Exception("InvalidArgument")
0039               << "[DeepBoostedJetFeatures::check_consistency()] Inconsistent variable length " << get(names[i]).size()
0040               << " for " << names[i] << ", should be " << ref_len;
0041         }
0042       }
0043     }
0044 
0045     const std::vector<float>& get(const std::string& name) const {
0046       auto item = feature_map_.find(name);
0047       if (item != feature_map_.end()) {
0048         return item->second;
0049       } else {
0050         throw cms::Exception("InvalidArgument")
0051             << "[DeepBoostedJetFeatures::get()] Feature " << name << " does not exist!";
0052       }
0053     }
0054 
0055   private:
0056     bool is_empty_ = true;
0057     std::unordered_map<std::string, std::vector<float>> feature_map_;
0058   };
0059 
0060 }  // namespace btagbtvdeep
0061 
0062 #endif  // DataFormats_BTauReco_DeepBoostedJetFeatures_h