CMS 3D CMS Logo

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 
14 
15 #include <vector>
16 #include <string>
17 
19 
20  public:
21 
22  // Define here the number and the meaning of the categories
23  // for this specific MVA
24  const int nCategories = 3;
26  UNDEFINED = -1,
30  };
31 
32  // Define the struct that contains all necessary for MVA variables
33  // Note: all variables have to be floats for TMVA Reader, even if
34  // the training was done with ints.
35  struct AllVariables {
36  // Pure ECAL -> shower shapes
37  float see; // 0
38  float spp; // 1
39  float OneMinusE1x5E5x5; // 2
40  float R9; // 3
41  float etawidth; // 4
42  float phiwidth; // 5
43  float HoE; // 6
44  // Endcap only variables
45  float PreShowerOverRaw; // 7
46  //Pure tracking variables
47  float kfhits; // 8
48  float kfchi2; // 9
49  float gsfchi2; // 10
50  // Energy matching
51  float fbrem; // 11
52 
53  float gsfhits; // 12
55  float convVtxFitProbability; // 14
56 
57  float EoP; // 15
58  float eleEoPout; // 16
59  float IoEmIoP; // 17
60  // Geometrical matchings
61  float deta; // 18
62  float dphi; // 19
63  float detacalo; // 20
64  // Spectator variables
65  float pt; // 21
66  float isBarrel; // 22
67  float isEndcap; // 23
68  float SCeta; // 24
69  //
70  float eClass; // 25
71  float pfRelIso; // 26
72  float expectedInnerHits; // 27
73  float vtxconv; // 28
74  float mcEventWeight; // 29
75  float mcCBmatchingCategory; // 30
76 
77  };
78 
79  // Constructor and destructor
81  ElectronMVAEstimatorRun2Spring16GeneralPurpose(); // For Reflex. Not to be used in reality
82  ElectronMVAEstimatorRun2Spring16GeneralPurpose(const std::string &mvaTag, const std::string &conversionsTag = "reducedEgamma:reducedConversions", const std::string &beamspotTag = "offlineBeamSpot");
83  void init(const std::vector <std::string> weightFileNames);
85 
86 
87 
88  // Calculation of the MVA value (VID accessor)
89  float mvaValue( const edm::Ptr<reco::Candidate>& particle, const edm::Event&) const override;
90  // Calculation of the MVA value (fwlite-compatible accessor)
91  float mvaValue( const reco::GsfElectron * particle, const edm::EventBase &) const ;
92  // Calculation of the MVA value (bare version)
93  float mvaValue( const int iCategory, const std::vector<float> & vars) const ;
94 
95  // Utility functions
96  int getNCategories() const override { return nCategories; }
97  bool isEndcapCategory( int category ) const;
98  const std::string& getName() const final { return name_; }
99  const std::string& getTag() const final { return tag_; }
100 
101  // Functions that should work on both pat and reco electrons
102  // (use the fact that pat::Electron inherits from reco::GsfElectron)
103  std::vector<float> fillMVAVariables(const edm::Ptr<reco::Candidate>& particle, const edm::Event&) const override;
104  std::vector<float> fillMVAVariables( const reco::GsfElectron * particle, const edm::Handle<reco::ConversionCollection> conversions, const reco::BeamSpot *beamSpot) const ;
105  int findCategory( const edm::Ptr<reco::Candidate>& particle) const override;
106  int findCategory( const reco::GsfElectron * particle) const ;
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 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.
122  const std::string name_ = "ElectronMVAEstimatorRun2Spring16GeneralPurpose";
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.
127 
128  // Data members
129  std::vector< std::unique_ptr<const GBRForest> > gbrForest_s;
130 
131  // All variables needed by this MVA
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 
147 #endif
void init(const std::vector< std::string > weightFileNames)
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
int findCategory(const edm::Ptr< reco::Candidate > &particle) const override