CMS 3D CMS Logo

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