CMS 3D CMS Logo

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