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 
18 public:
19  TMVAEvaluator();
20 
22  const std::vector<std::string>& variables, const std::vector<std::string>& spectators,
23  bool useGBRForest = false, bool useAdaBoost = false);
24 
25  void initializeGBRForest(const GBRForest* gbrForest, const std::vector<std::string>& variables,
26  const std::vector<std::string>& spectators, bool useAdaBoost = false);
27 
28  void initializeGBRForest(const edm::EventSetup& iSetup, const std::string& label,
29  const std::vector<std::string>& variables, const std::vector<std::string>& spectators,
30  bool useAdaBoost = false);
31 
32  float evaluateTMVA(const std::map<std::string, float>& inputs, bool useSpectators) const;
33  float evaluateGBRForest(const std::map<std::string, float>& inputs) const;
34  float evaluate(const std::map<std::string, float>& inputs, bool useSpectators = false) const;
35 
36 private:
40 
43  CMS_THREAD_GUARD(m_mutex) std::unique_ptr<TMVA::Reader> mReader;
44  std::shared_ptr<const GBRForest> mGBRForest;
45 
46  CMS_THREAD_GUARD(m_mutex) mutable std::map<std::string, std::pair<size_t, float>> mVariables;
47  CMS_THREAD_GUARD(m_mutex) mutable std::map<std::string, std::pair<size_t, float>> mSpectators;
48 };
49 
50 #endif // CommonTools_Utils_TMVAEvaluator_h
static boost::mutex mutex
Definition: Proxy.cc:11
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:46
bool mUsingGBRForest
Definition: TMVAEvaluator.h:38
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:44
std::string mMethod
Definition: TMVAEvaluator.h:41
std::map< std::string, std::pair< size_t, float > > mSpectators
Definition: TMVAEvaluator.h:47
std::mutex m_mutex
Definition: TMVAEvaluator.h:42
std::unique_ptr< TMVA::Reader > mReader
Definition: TMVAEvaluator.h:43
float evaluate(const std::map< std::string, float > &inputs, bool useSpectators=false) const
float evaluateGBRForest(const std::map< std::string, float > &inputs) const