test
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();
20 
21  void initialize(const std::string & options, const std::string & method, const std::string & weightFile,
22  const std::vector<std::string> & variables, const std::vector<std::string> & spectators, bool useGBRForest=false, bool useAdaBoost=false);
23  void initializeGBRForest(const GBRForest* gbrForest, const std::vector<std::string> & variables,
24  const std::vector<std::string> & spectators, bool useAdaBoost=false);
25  void initializeGBRForest(const edm::EventSetup &iSetup, const std::string & label,
26  const std::vector<std::string> & variables, const std::vector<std::string> & spectators, bool useAdaBoost=false);
27  float evaluateTMVA(const std::map<std::string,float> & inputs, bool useSpectators) const;
28  float evaluateGBRForest(const std::map<std::string,float> & inputs) const;
29  float evaluate(const std::map<std::string,float> & inputs, bool useSpectators=false) const;
30 
31  private:
35 
38  [[cms::thread_guard("m_mutex")]] std::unique_ptr<TMVA::Reader> mReader;
39  std::unique_ptr<TMVA::IMethod> mIMethod;
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 
std::map< std::string, std::pair< size_t, float > > mVariables
Definition: TMVAEvaluator.h:42
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:33
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
std::shared_ptr< const GBRForest > mGBRForest
Definition: TMVAEvaluator.h:40
std::string mMethod
Definition: TMVAEvaluator.h:36
std::mutex m_mutex
Definition: TMVAEvaluator.h:37
std::unique_ptr< TMVA::Reader > mReader
Definition: TMVAEvaluator.h:38
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:39