CMS 3D CMS Logo

TMVAEvaluator.h
Go to the documentation of this file.
1 #ifndef CommonTools_MVAUtils_TMVAEvaluator_h
2 #define CommonTools_MVAUtils_TMVAEvaluator_h
3 
4 #include <map>
5 #include <memory>
6 #include <mutex>
7 #include <string>
8 #include <vector>
9 
13 #include "TMVA/IMethod.h"
14 #include "TMVA/Reader.h"
15 
17 public:
18  TMVAEvaluator();
19 
20  void initialize(const std::string& options,
21  const std::string& method,
22  const std::string& weightFile,
23  const std::vector<std::string>& variables,
24  const std::vector<std::string>& spectators,
25  bool useGBRForest = false,
26  bool useAdaBoost = false);
27 
28  void initializeGBRForest(const GBRForest* gbrForest,
29  const std::vector<std::string>& variables,
30  const std::vector<std::string>& spectators,
31  bool useAdaBoost = false);
32 
33  void initializeGBRForest(const edm::EventSetup& iSetup,
34  const std::string& label,
35  const std::vector<std::string>& variables,
36  const std::vector<std::string>& spectators,
37  bool useAdaBoost = false);
38 
39  float evaluateTMVA(const std::map<std::string, float>& inputs, bool useSpectators) const;
40  float evaluateGBRForest(const std::map<std::string, float>& inputs) const;
41  float evaluate(const std::map<std::string, float>& inputs, bool useSpectators = false) const;
42 
43 private:
47 
50  CMS_THREAD_GUARD(m_mutex) std::unique_ptr<TMVA::Reader> mReader;
51  std::shared_ptr<const GBRForest> mGBRForest;
52 
53  CMS_THREAD_GUARD(m_mutex) mutable std::map<std::string, std::pair<size_t, float>> mVariables;
54  CMS_THREAD_GUARD(m_mutex) mutable std::map<std::string, std::pair<size_t, float>> mSpectators;
55 };
56 
57 #endif // CommonTools_Utils_TMVAEvaluator_h
static boost::mutex mutex
Definition: Proxy.cc:9
void initializeGBRForest(const GBRForest *gbrForest, const std::vector< std::string > &variables, const std::vector< std::string > &spectators, bool useAdaBoost=false)
std::map< std::string, std::pair< size_t, float > > mVariables
Definition: TMVAEvaluator.h:53
bool mUsingGBRForest
Definition: TMVAEvaluator.h:45
void initialize(const std::string &options, const std::string &method, const std::string &weightFile, const std::vector< std::string > &variables, const std::vector< std::string > &spectators, bool useGBRForest=false, bool useAdaBoost=false)
char const * label
float evaluateTMVA(const std::map< std::string, float > &inputs, bool useSpectators) const
#define CMS_THREAD_GUARD(_var_)
std::shared_ptr< const GBRForest > mGBRForest
Definition: TMVAEvaluator.h:51
std::string mMethod
Definition: TMVAEvaluator.h:48
std::map< std::string, std::pair< size_t, float > > mSpectators
Definition: TMVAEvaluator.h:54
std::mutex m_mutex
Definition: TMVAEvaluator.h:49
std::unique_ptr< TMVA::Reader > mReader
Definition: TMVAEvaluator.h:50
float evaluate(const std::map< std::string, float > &inputs, bool useSpectators=false) const
float evaluateGBRForest(const std::map< std::string, float > &inputs) const