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  float evaluateTMVA(const std::map<std::string, float>& inputs, bool useSpectators) const;
34  float evaluateGBRForest(const std::map<std::string, float>& inputs) const;
35  float evaluate(const std::map<std::string, float>& inputs, bool useSpectators = false) const;
36 
37 private:
41 
44  CMS_THREAD_GUARD(m_mutex) std::unique_ptr<TMVA::Reader> mReader;
45  std::shared_ptr<const GBRForest> mGBRForest;
46 
47  CMS_THREAD_GUARD(m_mutex) mutable std::map<std::string, std::pair<size_t, float>> mVariables;
48  CMS_THREAD_GUARD(m_mutex) mutable std::map<std::string, std::pair<size_t, float>> mSpectators;
49 };
50 
51 #endif // CommonTools_Utils_TMVAEvaluator_h
float evaluateTMVA(const std::map< std::string, float > &inputs, bool useSpectators) const
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:47
static std::mutex mutex
Definition: Proxy.cc:8
bool mUsingGBRForest
Definition: TMVAEvaluator.h:39
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)
#define CMS_THREAD_GUARD(_var_)
std::shared_ptr< const GBRForest > mGBRForest
Definition: TMVAEvaluator.h:45
std::string mMethod
Definition: TMVAEvaluator.h:42
float evaluate(const std::map< std::string, float > &inputs, bool useSpectators=false) const
std::map< std::string, std::pair< size_t, float > > mSpectators
Definition: TMVAEvaluator.h:48
std::mutex m_mutex
Definition: TMVAEvaluator.h:43
float evaluateGBRForest(const std::map< std::string, float > &inputs) const
std::unique_ptr< TMVA::Reader > mReader
Definition: TMVAEvaluator.h:44