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  void initializeGBRForest(const edm::EventSetup& iSetup,
34  const std::string& label,
35  const std::vector<std::string>& variables,
36  const std::vector<std::string>& spectators,
37  bool useAdaBoost = false);
38 
39  float evaluateTMVA(const std::map<std::string, float>& inputs, bool useSpectators) const;
40  float evaluateGBRForest(const std::map<std::string, float>& inputs) const;
41  float evaluate(const std::map<std::string, float>& inputs, bool useSpectators = false) const;
42 
43 private:
47 
50  CMS_THREAD_GUARD(m_mutex) std::unique_ptr<TMVA::Reader> mReader;
51  std::shared_ptr<const GBRForest> mGBRForest;
52 
53  CMS_THREAD_GUARD(m_mutex) mutable std::map<std::string, std::pair<size_t, float>> mVariables;
54  CMS_THREAD_GUARD(m_mutex) mutable std::map<std::string, std::pair<size_t, float>> mSpectators;
55 };
56 
57 #endif // CommonTools_Utils_TMVAEvaluator_h
TMVAEvaluator::evaluate
float evaluate(const std::map< std::string, float > &inputs, bool useSpectators=false) const
Definition: TMVAEvaluator.cc:146
TMVAEvaluator::mReader
std::unique_ptr< TMVA::Reader > mReader
Definition: TMVAEvaluator.h:50
TMVAEvaluator::mMethod
std::string mMethod
Definition: TMVAEvaluator.h:48
L1TEGammaDiff_cfi.variables
variables
Definition: L1TEGammaDiff_cfi.py:5
TMVAEvaluator::mUsingGBRForest
bool mUsingGBRForest
Definition: TMVAEvaluator.h:45
candidateCombinedMVAV2Computer_cfi.spectators
spectators
Definition: candidateCombinedMVAV2Computer_cfi.py:15
GBRForest
Definition: GBRForest.h:25
AlcaSiPixelAliHarvester0T_cff.method
method
Definition: AlcaSiPixelAliHarvester0T_cff.py:41
HLT_FULL_cff.weightFile
weightFile
Definition: HLT_FULL_cff.py:6711
TMVAEvaluator::mIsInitialized
bool mIsInitialized
Definition: TMVAEvaluator.h:44
GBRForest.h
TMVAEvaluator
Definition: TMVAEvaluator.h:16
options
Definition: options.py:1
TMVAEvaluator::evaluateGBRForest
float evaluateGBRForest(const std::map< std::string, float > &inputs) const
Definition: TMVAEvaluator.cc:121
HLT_FULL_cff.useAdaBoost
useAdaBoost
Definition: HLT_FULL_cff.py:6714
TMVAEvaluator::TMVAEvaluator
TMVAEvaluator()
Definition: TMVAEvaluator.cc:11
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
TMVAEvaluator::mVariables
std::map< std::string, std::pair< size_t, float > > mVariables
Definition: TMVAEvaluator.h:53
thread_safety_macros.h
TMVAEvaluator::m_mutex
std::mutex m_mutex
Definition: TMVAEvaluator.h:49
TMVAEvaluator::mGBRForest
std::shared_ptr< const GBRForest > mGBRForest
Definition: TMVAEvaluator.h:51
mutex
static std::mutex mutex
Definition: Proxy.cc:8
PixelMapPlotter.inputs
inputs
Definition: PixelMapPlotter.py:490
edm::EventSetup
Definition: EventSetup.h:58
TMVAEvaluator::mUseAdaBoost
bool mUseAdaBoost
Definition: TMVAEvaluator.h:46
TMVAEvaluator::initializeGBRForest
void initializeGBRForest(const GBRForest *gbrForest, const std::vector< std::string > &variables, const std::vector< std::string > &spectators, bool useAdaBoost=false)
Definition: TMVAEvaluator.cc:53
TMVAEvaluator::initialize
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)
Definition: TMVAEvaluator.cc:13
EventSetup.h
TMVAEvaluator::evaluateTMVA
float evaluateTMVA(const std::map< std::string, float > &inputs, bool useSpectators) const
Definition: TMVAEvaluator.cc:85
HLT_FULL_cff.useGBRForest
useGBRForest
Definition: HLT_FULL_cff.py:6713
CMS_THREAD_GUARD
#define CMS_THREAD_GUARD(_var_)
Definition: thread_safety_macros.h:6
TMVAEvaluator::mSpectators
std::map< std::string, std::pair< size_t, float > > mSpectators
Definition: TMVAEvaluator.h:54
label
const char * label
Definition: PFTauDecayModeTools.cc:11