CMS 3D CMS Logo

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