CMS 3D CMS Logo

ElectronMVAEstimatorRun2Fall17.h
Go to the documentation of this file.
1 #ifndef RecoEgamma_ElectronIdentification_ElectronMVAEstimatorRun2Fall17_H
2 #define RecoEgamma_ElectronIdentification_ElectronMVAEstimatorRun2Fall17_H
3 
4 #include <vector>
5 #include <string>
6 
17 
19 
20  public:
21 
22  // Constructor and destructor
23  ElectronMVAEstimatorRun2Fall17(const edm::ParameterSet& conf, bool withIso);
25  // For use with FWLite/Python
27  const std::string &mvaName,
28  bool withIso,
29  const std::string &conversionsTag = "reducedEgamma:reducedConversions",
30  const std::string &beamspotTag = "offlineBeamSpot",
31  const double ptSplit = 10., // The category split parameters are taken over from the python configuration file
32  const double ebSplit = 0.800,
33  const double ebeeSplit = 1.479,
34  const bool debug = false);
35 
36  void init(const std::vector<std::string> &weightFileNames);
37  void setClips(const std::vector<double> &clipsLowerValues, const std::vector<double> &clipsUpperValues);
38 
39  // Calculation of the MVA value (VID accessor)
40  float mvaValue( const edm::Ptr<reco::Candidate>& particle, const edm::Event&) const override;
41  // Calculation of the MVA value (fwlite-compatible accessor)
42  float mvaValue( const reco::GsfElectron * particle, const edm::EventBase &) const ;
43  // Calculation of the MVA value (bare version)
44  float mvaValue( const int iCategory, const std::vector<float> & vars) const ;
45 
46  // Utility functions
47  int getNCategories() const override { return nCategories_; }
48  const std::string& getName() const final { return name_; }
49  const std::string& getTag() const final { return tag_; }
50 
51  // Functions that should work on both pat and reco electrons
52  // (use the fact that pat::Electron inherits from reco::GsfElectron)
53  std::vector<float> fillMVAVariables(const edm::Ptr<reco::Candidate>& particle, const edm::Event&) const override;
55  int findCategory( const edm::Ptr<reco::Candidate>& particle) const override;
56  int findCategory( const reco::GsfElectron * particle) const ;
57  // The function below ensures that the variables passed to MVA are
58  // within reasonable bounds
59  void constrainMVAVariables(std::vector<float>&) const;
60 
61  // Call this function once after the constructor to declare
62  // the needed event content pieces to the framework
63  void setConsumes(edm::ConsumesCollector&&) const final;
64 
65  protected:
66 
67  // This is a stuct to store an instruction of clipping one of the input variables with a lower or an upper limit
68  struct Clip {
69  unsigned int varIdx;
70  bool upper;
71  float value;
72  };
73 
74  // Define here the number and the meaning of the categories
75  // for this specific MVA
76  const int nCategories_ = 6;
77  const int nVar_ = 22;
79  UNDEFINED = -1,
86  };
87 
88  // MVA tag. This is an additional string variable to distinguish
89  // instances of the estimator of this class configured with different
90  // weight files.
92 
93  // MVA name. This is a unique name for this MVA implementation.
94  // It will be used as part of ValueMap names.
95  // For simplicity, keep it set to the class name.
96 
98 
99  // Data members
100  std::vector< std::unique_ptr<const GBRForest> > gbrForests_;
101 
103 
104  //
105  // Declare all labels and tokens that will be needed to retrieve misc
106  // data from the event content required by this MVA
107  //
112 
113  //edm::EDGetTokenT<reco::BeamSpot> beamSpotToken_;
114  //edm::EDGetTokenT<reco::ConversionCollection> conversionsTokenAOD_;
115  //edm::EDGetTokenT<reco::ConversionCollection> conversionsTokenMiniAOD_;
116  //edm::EDGetTokenT<double> rhoToken_;
117 
118  double ptSplit_; // we have high and low pt categories
119  double ebSplit_; // barrel is split into two regions
120  double ebeeSplit_; // division between barrel and endcap
121 
122  std::vector<std::string> varNames_;
123 
124  // To store the variable clipping operations
125  std::vector<Clip> clipsLower_;
126  std::vector<Clip> clipsUpper_;
127 
128  bool withIso_;
129 
130  bool debug_;
131 };
132 
133 #endif
void setClips(const std::vector< double > &clipsLowerValues, const std::vector< double > &clipsUpperValues)
void init(const std::vector< std::string > &weightFileNames)
std::vector< std::unique_ptr< const GBRForest > > gbrForests_
const std::string & getName() const final
ElectronMVAEstimatorRun2Fall17(const edm::ParameterSet &conf, bool withIso)
void constrainMVAVariables(std::vector< float > &) const
float mvaValue(const edm::Ptr< reco::Candidate > &particle, const edm::Event &) const override
#define debug
Definition: HDRShower.cc:19
int findCategory(const edm::Ptr< reco::Candidate > &particle) const override
std::vector< float > fillMVAVariables(const edm::Ptr< reco::Candidate > &particle, const edm::Event &) const override
const std::string & getTag() const final
void setConsumes(edm::ConsumesCollector &&) const final