CMS 3D CMS Logo

ElectronMVAEstimatorRun2.h
Go to the documentation of this file.
1 #ifndef RecoEgamma_ElectronIdentification_ElectronMVAEstimatorRun2_H
2 #define RecoEgamma_ElectronIdentification_ElectronMVAEstimatorRun2_H
3 
9 
10 // Note on Python/FWLite support:
11 //
12 // The ElectronMVAEstimatorRun2 is not only used in the full CMSSW framework
13 // via the AnyMVAEstimatorRun2Factory, but it is intended to also be used
14 // standalone in Python/FWLite. However, we want to avoid building dictionaries
15 // for the ElectronMVAEstimatorRun2 in this ElectronIdentification package,
16 // becase algorithms and data formats should not mix in CMSSW.
17 // That's why it has to be possible to create the dictionaries on the fly, for
18 // example by running this line in a Python script:
19 //
20 // ```Python
21 // ROOT.gInterpreter.Declare('#include "RecoEgamma/ElectronIdentification/interface/ElectronMVAEstimatorRun2.h"')
22 // ```
23 //
24 // To speed up the dictionary generation and avoid errors caused by conflicting
25 // C++ modules, we try to forwar declare as much as possible in
26 // ElectronMVAEstimatorRun2.h and AnyMVAEstimatorRun2Base.h.
27 
28 namespace reco {
29  class GsfElectron;
30 }
31 
33 public:
34  // Constructor
36  // For use with FWLite/Python
38  const std::string& mvaName,
39  int nCategories,
41  const std::vector<std::string>& categoryCutStrings,
42  const std::vector<std::string>& weightFileNames,
43  bool debug = false);
44 
45  // Calculation of the MVA value
46  float mvaValue(const reco::Candidate* candidate,
47  std::vector<float> const& auxVariables,
48  int& iCategory) const override;
49 
50  // for FWLite just passing rho
51  float mvaValue(const reco::Candidate* candidate, float rho, int& iCategory) const {
52  return mvaValue(candidate, std::vector<float>{rho}, iCategory);
53  }
54 
55  int findCategory(const reco::Candidate* candidate) const override;
56 
57 private:
58  void init(const std::vector<std::string>& weightFileNames);
59 
60  int findCategory(reco::GsfElectron const& electron) const;
61 
62  std::vector<ThreadSafeFunctor<StringCutObjectSelector<reco::GsfElectron>>> categoryFunctions_;
63  std::vector<int> nVariables_;
64 
65  // Data members
66  std::vector<std::unique_ptr<const GBRForest>> gbrForests_;
67 
68  // There might be different variables for each category, so the variables
69  // names vector is itself a vector of length nCategories
70  std::vector<std::vector<int>> variables_;
71 
73 };
74 
75 #endif
MVAVariableManager< reco::GsfElectron > mvaVarMngr_
std::vector< ThreadSafeFunctor< StringCutObjectSelector< reco::GsfElectron > > > categoryFunctions_
ElectronMVAEstimatorRun2(const edm::ParameterSet &conf)
void init(const std::vector< std::string > &weightFileNames)
std::vector< std::vector< int > > variables_
#define debug
Definition: HDRShower.cc:19
fixed size matrix
float mvaValue(const reco::Candidate *candidate, std::vector< float > const &auxVariables, int &iCategory) const override
float mvaValue(const reco::Candidate *candidate, float rho, int &iCategory) const
std::vector< std::unique_ptr< const GBRForest > > gbrForests_
int findCategory(const reco::Candidate *candidate) const override