CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ElectronMVAEstimatorRun2Spring15NonTrig.h
Go to the documentation of this file.
1 #ifndef RecoEgamma_ElectronIdentification_ElectronMVAEstimatorRun2Spring15NonTrig_H
2 #define RecoEgamma_ElectronIdentification_ElectronMVAEstimatorRun2Spring15NonTrig_H
3 
5 
7 
9 
13 
15 
16 #include <vector>
17 #include <string>
18 #include <TROOT.h>
19 #include "TMVA/Factory.h"
20 #include "TMVA/Tools.h"
21 #include "TMVA/Reader.h"
22 
24 
25  public:
26 
27  // Define here the number and the meaning of the categories
28  // for this specific MVA
29  const int nCategories = 6;
31  UNDEFINED = -1,
38  };
39 
40  // Define the struct that contains all necessary for MVA variables
41  // Note: all variables have to be floats for TMVA Reader, even if
42  // the training was done with ints.
43  struct AllVariables {
44  // Pure ECAL -> shower shapes
45  float see; // 0
46  float spp; // 1
47  float OneMinusE1x5E5x5; // 2
48  float R9; // 3
49  float etawidth; // 4
50  float phiwidth; // 5
51  float HoE; // 6
52  // Endcap only variables
53  float PreShowerOverRaw; // 7
54  //Pure tracking variables
55  float kfhits; // 8
56  float kfchi2; // 9
57  float gsfchi2; // 10
58  // Energy matching
59  float fbrem; // 11
60 
61  float gsfhits; // 12
63  float convVtxFitProbability; // 14
64 
65  float EoP; // 15
66  float eleEoPout; // 16
67  float IoEmIoP; // 17
68  // Geometrical matchings
69  float deta; // 18
70  float dphi; // 19
71  float detacalo; // 20
72  // Spectator variables
73  float pt; // 21
74  float isBarrel; // 22
75  float isEndcap; // 23
76  float SCeta; // 24
77  //
78  float eClass; // 25
79  float pfRelIso; // 26
80  float expectedInnerHits; // 27
81  float vtxconv; // 28
82  float mcEventWeight; // 29
83  float mcCBmatchingCategory; // 30
84 
85  };
86 
87  // Constructor and destructor
90 
91  // Calculation of the MVA value
92  float mvaValue( const edm::Ptr<reco::Candidate>& particle, const edm::Event&) const override;
93 
94  // Utility functions
95  std::unique_ptr<const GBRForest> createSingleReader(const int iCategory,
96  const edm::FileInPath &weightFile);
97 
98  virtual int getNCategories() const override { return nCategories; }
99  bool isEndcapCategory( int category ) const;
100  virtual const std::string& getName() const override final { return _name; }
101  virtual const std::string& getTag() const override final { return _tag; }
102 
103  // Functions that should work on both pat and reco electrons
104  // (use the fact that pat::Electron inherits from reco::GsfElectron)
105  std::vector<float> fillMVAVariables(const edm::Ptr<reco::Candidate>& particle, const edm::Event&) const override;
106  int findCategory( const edm::Ptr<reco::Candidate>& particle) const override;
107  // The function below ensures that the variables passed to MVA are
108  // within reasonable bounds
109  void constrainMVAVariables(AllVariables&) const;
110 
111  // Call this function once after the constructor to declare
112  // the needed event content pieces to the framework
113  void setConsumes(edm::ConsumesCollector&&) const override final;
114  // Call this function once per event to retrieve all needed
115  // event content pices
116 
117  private:
118 
119  // MVA name. This is a unique name for this MVA implementation.
120  // It will be used as part of ValueMap names.
121  // For simplicity, keep it set to the class name.
123  // MVA tag. This is an additional string variable to distinguish
124  // instances of the estimator of this class configured with different
125  // weight files.
126  const std::string _tag;
127 
128  // Data members
129  std::vector< std::unique_ptr<const GBRForest> > _gbrForests;
130 
131  // All variables needed by this MVA
132  const std::string _MethodName;
134 
135  //
136  // Declare all tokens that will be needed to retrieve misc
137  // data from the event content required by this MVA
138  //
140  // Conversions in AOD and miniAOD have different names
143 
144 
145 };
146 
148  ElectronMVAEstimatorRun2Spring15NonTrig,
149  "ElectronMVAEstimatorRun2Spring15NonTrig");
150 
151 #endif
std::vector< std::unique_ptr< const GBRForest > > _gbrForests
std::unique_ptr< const GBRForest > createSingleReader(const int iCategory, const edm::FileInPath &weightFile)
int findCategory(const edm::Ptr< reco::Candidate > &particle) const override
virtual const std::string & getName() const overridefinal
std::vector< float > fillMVAVariables(const edm::Ptr< reco::Candidate > &particle, const edm::Event &) const override
virtual const std::string & getTag() const overridefinal
tuple conf
Definition: dbtoconf.py:185
string const
Definition: compareJSON.py:14
void setConsumes(edm::ConsumesCollector &&) const overridefinal
#define private
Definition: FWFileEntry.h:17
#define DEFINE_EDM_PLUGIN(factory, type, name)
float mvaValue(const edm::Ptr< reco::Candidate > &particle, const edm::Event &) const override