CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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"
14 
15 
17 
18  public:
19  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:
37 
40  [[cms::thread_guard("m_mutex")]] std::unique_ptr<TMVA::Reader> mReader;
41  std::unique_ptr<TMVA::IMethod> mIMethod;
42  std::unique_ptr<const GBRForest> mGBRForest;
43 
44  [[cms::thread_guard("m_mutex")]] mutable std::map<std::string,std::pair<size_t,float>> mVariables;
45  [[cms::thread_guard("m_mutex")]] mutable std::map<std::string,std::pair<size_t,float>> mSpectators;
46 };
47 
48 #endif // CommonTools_Utils_TMVAEvaluator_h
49 
std::map< std::string, std::pair< size_t, float > > mVariables
Definition: TMVAEvaluator.h:44
static boost::mutex mutex
Definition: LHEProxy.cc:11
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:45
float evaluateTMVA(const std::map< std::string, float > &inputs, bool useSpectators) const
std::string mMethod
Definition: TMVAEvaluator.h:38
std::mutex m_mutex
Definition: TMVAEvaluator.h:39
std::unique_ptr< TMVA::Reader > mReader
Definition: TMVAEvaluator.h:40
std::unique_ptr< const GBRForest > mGBRForest
Definition: TMVAEvaluator.h:42
float evaluate(const std::map< std::string, float > &inputs, bool useSpectators=false) const
float evaluateGBRForest(const std::map< std::string, float > &inputs) const
std::unique_ptr< TMVA::IMethod > mIMethod
Definition: TMVAEvaluator.h:41