CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Protected Types | Protected Attributes
ElectronMVAEstimatorRun2Fall17 Class Reference

#include <ElectronMVAEstimatorRun2Fall17.h>

Inheritance diagram for ElectronMVAEstimatorRun2Fall17:
AnyMVAEstimatorRun2Base ElectronMVAEstimatorRun2Fall17Iso ElectronMVAEstimatorRun2Fall17NoIso

Classes

struct  Clip
 

Public Member Functions

void constrainMVAVariables (std::vector< float > &) const
 
 ElectronMVAEstimatorRun2Fall17 (const edm::ParameterSet &conf, bool withIso)
 
 ElectronMVAEstimatorRun2Fall17 (const std::string &mvaTag, const std::string &mvaName, bool withIso, const std::string &conversionsTag="reducedEgamma:reducedConversions", const std::string &beamspotTag="offlineBeamSpot", const double ptSplit=10., const double ebSplit=0.800, const double ebeeSplit=1.479, const bool debug=false)
 
std::vector< float > fillMVAVariables (const edm::Ptr< reco::Candidate > &particle, const edm::Event &) const override
 
std::vector< float > fillMVAVariables (const reco::GsfElectron *particle, const edm::Handle< reco::ConversionCollection > conversions, const reco::BeamSpot *beamSpot, const edm::Handle< double > rho) const
 
int findCategory (const edm::Ptr< reco::Candidate > &particle) const override
 
int findCategory (const reco::GsfElectron *particle) const
 
const std::string & getName () const final
 
int getNCategories () const override
 
const std::string & getTag () const final
 
void init (const std::vector< std::string > &weightFileNames)
 
float mvaValue (const edm::Ptr< reco::Candidate > &particle, const edm::Event &) const override
 
float mvaValue (const reco::GsfElectron *particle, const edm::EventBase &) const
 
float mvaValue (const int iCategory, const std::vector< float > &vars) const
 
void setClips (const std::vector< double > &clipsLowerValues, const std::vector< double > &clipsUpperValues)
 
void setConsumes (edm::ConsumesCollector &&) const final
 
 ~ElectronMVAEstimatorRun2Fall17 () override
 
- Public Member Functions inherited from AnyMVAEstimatorRun2Base
 AnyMVAEstimatorRun2Base (const edm::ParameterSet &conf)
 
virtual void getEventContent (const edm::Event &iEvent) const final
 
template<typename... Args>
std::vector< float > packMVAVariables (const Args...args) const
 
virtual ~AnyMVAEstimatorRun2Base ()
 

Protected Types

enum  MVACategories_ {
  UNDEFINED = -1, CAT_EB1_PTLow = 0, CAT_EB2_PTLow = 1, CAT_EE_PTLow = 2,
  CAT_EB1_PTHig = 3, CAT_EB2_PTHig = 4, CAT_EE_PTHig = 5
}
 

Protected Attributes

const edm::InputTag beamSpotLabel_
 
std::vector< ClipclipsLower_
 
std::vector< ClipclipsUpper_
 
const edm::InputTag conversionsLabelAOD_
 
const edm::InputTag conversionsLabelMiniAOD_
 
bool debug_
 
double ebeeSplit_
 
double ebSplit_
 
std::vector< std::unique_ptr< const GBRForest > > gbrForests_
 
const std::string methodName_
 
const std::string name_
 
const int nCategories_ = 6
 
const int nVar_ = 22
 
double ptSplit_
 
const edm::InputTag rhoLabel_
 
const std::string tag_
 
std::vector< std::string > varNames_
 
bool withIso_
 

Additional Inherited Members

- Public Attributes inherited from AnyMVAEstimatorRun2Base
const edm::ParameterSet _conf
 

Detailed Description

Definition at line 18 of file ElectronMVAEstimatorRun2Fall17.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

ElectronMVAEstimatorRun2Fall17::ElectronMVAEstimatorRun2Fall17 ( const edm::ParameterSet conf,
bool  withIso 
)

Definition at line 3 of file ElectronMVAEstimatorRun2Fall17.cc.

References debug_, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), init(), setClips(), mvaElectronID_Fall17_iso_V1_cff::weightFileNames, and withIso_.

3  :
5  tag_(conf.getParameter<std::string>("mvaTag")),
6  name_(conf.getParameter<std::string>("mvaName")),
7  methodName_("BDTG method"),
8  beamSpotLabel_ (conf.getParameter<edm::InputTag> ("beamSpot")),
9  conversionsLabelAOD_ (conf.getParameter<edm::InputTag> ("conversionsAOD")),
10  conversionsLabelMiniAOD_(conf.getParameter<edm::InputTag> ("conversionsMiniAOD")),
11  rhoLabel_ (edm::InputTag ("fixedGridRhoFastjetAll")),
12  ptSplit_ (conf.getParameter<double> ("ptSplit")),
13  ebSplit_ (conf.getParameter<double> ("ebSplit")),
14  ebeeSplit_ (conf.getParameter<double> ("ebeeSplit")),
15  varNames_ (conf.getParameter<std::vector<std::string>>("varNames"))
16 {
17 
18  const std::vector <std::string> weightFileNames
19  = conf.getParameter<std::vector<std::string> >("weightFileNames");
20 
21  std::vector<double> clipsLowerValues = conf.getParameter<std::vector<double>>("clipLower");
22  std::vector<double> clipsUpperValues = conf.getParameter<std::vector<double>>("clipUpper");
23 
24  // Initialize GBRForests and and clipping instructions
25  init(weightFileNames);
26  setClips(clipsLowerValues, clipsUpperValues);
27 
28  withIso_ = withIso;
29  debug_ = conf.getUntrackedParameter<bool>("debug", false);
30 
31 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
void setClips(const std::vector< double > &clipsLowerValues, const std::vector< double > &clipsUpperValues)
AnyMVAEstimatorRun2Base(const edm::ParameterSet &conf)
void init(const std::vector< std::string > &weightFileNames)
ElectronMVAEstimatorRun2Fall17::~ElectronMVAEstimatorRun2Fall17 ( )
override

Definition at line 102 of file ElectronMVAEstimatorRun2Fall17.cc.

Referenced by setClips().

102  {
103 }
ElectronMVAEstimatorRun2Fall17::ElectronMVAEstimatorRun2Fall17 ( const std::string &  mvaTag,
const std::string &  mvaName,
bool  withIso,
const std::string &  conversionsTag = "reducedEgamma:reducedConversions",
const std::string &  beamspotTag = "offlineBeamSpot",
const double  ptSplit = 10.,
const double  ebSplit = 0.800,
const double  ebeeSplit = 1.479,
const bool  debug = false 
)

Definition at line 33 of file ElectronMVAEstimatorRun2Fall17.cc.

References debug, debug_, and withIso_.

35  :
37  tag_ (mvaTag),
38  name_ (mvaName),
39  methodName_ ("BDTG method"),
40  beamSpotLabel_ (edm::InputTag(beamspotTag)),
41  conversionsLabelAOD_ (edm::InputTag(conversionsTag)),
43  rhoLabel_ (edm::InputTag("fixedGridRhoFastjetAll")),
44  ptSplit_ (ptSplit),
45  ebSplit_ (ebSplit),
47 {
48 
49  // Set if this is the ID with or without PF isolations
50  withIso_ = withIso;
51 
52  // Set debug flag
53  debug_ = debug;
54 
55 }
AnyMVAEstimatorRun2Base(const edm::ParameterSet &conf)
#define debug
Definition: HDRShower.cc:19

Member Function Documentation

void ElectronMVAEstimatorRun2Fall17::constrainMVAVariables ( std::vector< float > &  vars) const

Definition at line 456 of file ElectronMVAEstimatorRun2Fall17.cc.

References clip(), clipsLower_, and clipsUpper_.

Referenced by fillMVAVariables(), and getTag().

456  {
457 
458  // Check that variables do not have crazy values
459 
460  for(auto const& clip: clipsLower_) {
461  if ( vars[clip.varIdx] < clip.value ) {
462  vars[clip.varIdx] = clip.value;
463  }
464  }
465 
466  for(auto const& clip: clipsUpper_) {
467  if ( vars[clip.varIdx] > clip.value ) {
468  vars[clip.varIdx] = clip.value;
469  }
470  }
471 
472 }
T clip(const T &n, const T &lower, const T &upper)
std::vector< float > ElectronMVAEstimatorRun2Fall17::fillMVAVariables ( const edm::Ptr< reco::Candidate > &  particle,
const edm::Event iEvent 
) const
overridevirtual

Implements AnyMVAEstimatorRun2Base.

Definition at line 252 of file ElectronMVAEstimatorRun2Fall17.cc.

References beamSpotLabel_, conversions_cfi::conversions, conversionsLabelAOD_, conversionsLabelMiniAOD_, Exception, edm::Ptr< T >::get(), edm::Event::getByLabel(), edm::HandleBase::isValid(), nullptr, edm::Handle< T >::product(), and rhoLabel_.

Referenced by findCategory(), getTag(), and mvaValue().

252  {
253 
254  //
255  // Declare all value maps corresponding to the products we defined earlier
256  //
257  edm::Handle<double> theRho;
258  edm::Handle<reco::BeamSpot> theBeamSpot;
260 
261  iEvent.getByLabel(rhoLabel_, theRho);
262 
263  // Get data needed for conversion rejection
264  iEvent.getByLabel(beamSpotLabel_, theBeamSpot);
265 
266  // Conversions in miniAOD and AOD have different names,
267  // but the same type, so we use the same handle with different tokens.
268  iEvent.getByLabel(conversionsLabelAOD_, conversions);
269  if( !conversions.isValid() ) {
270  iEvent.getByLabel(conversionsLabelMiniAOD_, conversions);
271  }
272 
273  // Make sure everything is retrieved successfully
274  if(! (theBeamSpot.isValid()
275  && conversions.isValid() )
276  ) {
277  throw cms::Exception("MVA failure: ")
278  << "Failed to retrieve event content needed for this MVA"
279  << std::endl
280  << "Check python MVA configuration file."
281  << std::endl;
282  }
283 
284  // Try to cast the particle into a reco particle.
285  // This should work for both reco and pat.
286  const edm::Ptr<reco::GsfElectron> eleRecoPtr = ( edm::Ptr<reco::GsfElectron> )particle;
287  if( eleRecoPtr.get() == nullptr ) {
288  throw cms::Exception("MVA failure: ")
289  << " given particle is expected to be reco::GsfElectron or pat::Electron," << std::endl
290  << " but appears to be neither" << std::endl;
291  }
292 
293  return fillMVAVariables(eleRecoPtr.get(), conversions, theBeamSpot.product(), theRho);
294 }
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:159
#define nullptr
bool isValid() const
Definition: HandleBase.h:74
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:475
T const * product() const
Definition: Handle.h:81
std::vector< float > fillMVAVariables(const edm::Ptr< reco::Candidate > &particle, const edm::Event &) const override
std::vector< float > ElectronMVAEstimatorRun2Fall17::fillMVAVariables ( const reco::GsfElectron particle,
const edm::Handle< reco::ConversionCollection conversions,
const reco::BeamSpot beamSpot,
const edm::Handle< double >  rho 
) const

Definition at line 298 of file ElectronMVAEstimatorRun2Fall17.cc.

References reco::Vertex::chi2(), pat::Electron::closestCtfTrackRef(), reco::GsfElectron::closestCtfTrackRef(), constrainMVAVariables(), reco::GsfElectron::deltaEtaSeedClusterTrackAtCalo(), reco::GsfElectron::deltaEtaSuperClusterTrackAtVtx(), reco::GsfElectron::deltaPhiSuperClusterTrackAtVtx(), reco::GsfElectron::ecalEnergy(), reco::GsfElectron::eEleClusterOverPout(), reco::GsfElectron::eSuperClusterOverP(), reco::GsfElectron::fbrem(), objects.autophobj::float, reco::GsfElectron::full5x5_e1x5(), reco::GsfElectron::full5x5_e5x5(), reco::GsfElectron::full5x5_hcalOverEcal(), reco::GsfElectron::full5x5_r9(), reco::GsfElectron::full5x5_sigmaIetaIeta(), reco::GsfElectron::full5x5_sigmaIphiIphi(), edm::Ref< C, T, F >::get(), reco::GsfElectron::gsfTrack(), electrons_cff::hoe, edm::Ref< C, T, F >::isAvailable(), edm::Ref< C, T, F >::isNonnull(), edm::Ref< C, T, F >::isNull(), reco::Vertex::isValid(), ConversionTools::matchedConversion(), reco::HitPattern::MISSING_INNER_HITS, reco::Vertex::ndof(), AnyMVAEstimatorRun2Base::packMVAVariables(), reco::GsfElectron::pfIsolationVariables(), reco::BeamSpot::position(), electrons_cff::r9, reco::GsfElectron::superCluster(), reco::GsfElectron::trackMomentumAtVtx(), badGlobalMuonTaggersAOD_cff::vtx, and withIso_.

298  {
299 
300 
301  // Both pat and reco particles have exactly the same accessors, so we use a reco ptr
302  // throughout the code, with a single exception as of this writing, handled separately below.
303  auto superCluster = eleRecoPtr->superCluster();
304 
305  // Pure ECAL -> shower shapes
306  float see = eleRecoPtr->full5x5_sigmaIetaIeta();
307  float spp = eleRecoPtr->full5x5_sigmaIphiIphi();
308  float circularity = 1. - eleRecoPtr->full5x5_e1x5() / eleRecoPtr->full5x5_e5x5();
309  float r9 = eleRecoPtr->full5x5_r9();
310  float etawidth = superCluster->etaWidth();
311  float phiwidth = superCluster->phiWidth();
312  float hoe = eleRecoPtr->full5x5_hcalOverEcal(); //hadronicOverEm();
313  // Endcap only variables
314  float preShowerOverRaw = superCluster->preshowerEnergy() / superCluster->rawEnergy();
315 
316  // To get to CTF track information in pat::Electron, we have to have the pointer
317  // to pat::Electron, it is not accessible from the pointer to reco::GsfElectron.
318  // This behavior is reported and is expected to change in the future (post-7.4.5 some time).
319  bool validKF= false;
320  reco::TrackRef myTrackRef = eleRecoPtr->closestCtfTrackRef();
321  const pat::Electron * elePatPtr = dynamic_cast<const pat::Electron *>(eleRecoPtr);
322  // Check if this is really a pat::Electron, and if yes, get the track ref from this new
323  // pointer instead
324  if( elePatPtr != nullptr ) {
325  myTrackRef = elePatPtr->closestCtfTrackRef();
326  }
327  validKF = (myTrackRef.isAvailable() && (myTrackRef.isNonnull()) );
328 
329  //Pure tracking variables
330  float kfhits = (validKF) ? myTrackRef->hitPattern().trackerLayersWithMeasurement() : -1. ;
331  float kfchi2 = (validKF) ? myTrackRef->normalizedChi2() : 0;
332  float gsfchi2 = eleRecoPtr->gsfTrack()->normalizedChi2();
333 
334  // Energy matching
335  float fbrem = eleRecoPtr->fbrem();
336 
337  float gsfhits = eleRecoPtr->gsfTrack()->hitPattern().trackerLayersWithMeasurement();
338  float expectedMissingInnerHits = eleRecoPtr->gsfTrack()
339  ->hitPattern().numberOfLostHits(reco::HitPattern::MISSING_INNER_HITS);
340 
342  conversions,
343  theBeamSpot->position());
344  float convVtxFitProbability = -1.;
345  if(!convRef.isNull()) {
346  const reco::Vertex &vtx = convRef.get()->conversionVertex();
347  if (vtx.isValid()) {
348  convVtxFitProbability = (float)TMath::Prob( vtx.chi2(), vtx.ndof());
349  }
350  }
351 
352  float eop = eleRecoPtr->eSuperClusterOverP();
353  float eleeopout = eleRecoPtr->eEleClusterOverPout();
354  float pAtVertex = eleRecoPtr->trackMomentumAtVtx().R();
355  float oneOverEminusOneOverP = (1.0/eleRecoPtr->ecalEnergy()) - (1.0 / pAtVertex );
356 
357  // Geometrical matchings
358  float deta = eleRecoPtr->deltaEtaSuperClusterTrackAtVtx();
359  float dphi = eleRecoPtr->deltaPhiSuperClusterTrackAtVtx();
360  float detacalo = eleRecoPtr->deltaEtaSeedClusterTrackAtCalo();
361 
362  if(withIso_)
363  {
364 
365  // Isolation variables
366  float pfChargedHadIso = (eleRecoPtr->pfIsolationVariables()).sumChargedHadronPt ; //chargedHadronIso();
367  float pfNeutralHadIso = (eleRecoPtr->pfIsolationVariables()).sumNeutralHadronEt ; //neutralHadronIso();
368  float pfPhotonIso = (eleRecoPtr->pfIsolationVariables()).sumPhotonEt; //photonIso();
369 
370  /*
371  * Packing variables for the MVA evaluation.
372  * CAREFUL: It is critical that all the variables that are packed into “vars” are
373  * exactly in the order they are found in the weight files
374  */
375  std::vector<float> vars = packMVAVariables(
376  see, // 0
377  spp, // 1
378  circularity,
379  r9,
380  etawidth,
381  phiwidth, // 5
382  hoe,
383  //Pure tracking variables
384  kfhits,
385  kfchi2,
386  gsfchi2, // 9
387  // Energy matching
388  fbrem,
389  gsfhits,
390  expectedMissingInnerHits,
391  convVtxFitProbability, // 13
392  eop,
393  eleeopout, // 15
394  oneOverEminusOneOverP,
395  // Geometrical matchings
396  deta, // 17
397  dphi,
398  detacalo,
399  // Isolation variables
400  pfPhotonIso,
401  pfChargedHadIso,
402  pfNeutralHadIso,
403  // Pileup
404  (float)*rho,
405 
406  // Endcap only variables NOTE: we don't need
407  // to check if we are actually in the endcap
408  // or not, as it is the last variable in the
409  // vector and it will be ignored by the
410  // GBRForest for the barrel.
411  //
412  // The GBRForest classification just needs an
413  // array with the input variables in the
414  // right order, what comes after doesn't
415  // matter.
416  preShowerOverRaw // 24
417  );
418 
419  constrainMVAVariables(vars);
420 
421  return vars;
422  }
423  else
424  {
425  std::vector<float> vars = packMVAVariables(
426  see, // 0
427  spp, // 1
428  circularity,
429  r9,
430  etawidth,
431  phiwidth, // 5
432  hoe,
433  kfhits,
434  kfchi2,
435  gsfchi2, // 9
436  fbrem,
437  gsfhits,
438  expectedMissingInnerHits,
439  convVtxFitProbability, // 13
440  eop,
441  eleeopout, // 15
442  oneOverEminusOneOverP,
443  deta, // 17
444  dphi,
445  detacalo,
446  (float)*rho,
447  preShowerOverRaw // 21
448  );
449 
450  constrainMVAVariables(vars);
451 
452  return vars;
453  }
454 }
bool isAvailable() const
Definition: Ref.h:577
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:253
bool isValid() const
Tells whether the vertex is valid.
Definition: Vertex.h:68
std::vector< float > packMVAVariables(const Args...args) const
double chi2() const
chi-squares
Definition: Vertex.h:98
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:245
void constrainMVAVariables(std::vector< float > &) const
bool isNull() const
Checks for null.
Definition: Ref.h:250
double ndof() const
Definition: Vertex.h:105
Analysis-level electron class.
Definition: Electron.h:52
reco::TrackRef closestCtfTrackRef() const override
override the reco::GsfElectron::closestCtfTrackRef method, to access the internal storage of the trac...
static reco::ConversionRef matchedConversion(const reco::GsfElectron &ele, const edm::Handle< reco::ConversionCollection > &convCol, const math::XYZPoint &beamspot, bool allowCkfMatch=true, float lxyMin=2.0, float probMin=1e-6, unsigned int nHitsBeforeVtxMax=0)
int ElectronMVAEstimatorRun2Fall17::findCategory ( const edm::Ptr< reco::Candidate > &  particle) const
overridevirtual

Implements AnyMVAEstimatorRun2Base.

Definition at line 200 of file ElectronMVAEstimatorRun2Fall17.cc.

References Exception, edm::Ptr< T >::get(), and nullptr.

Referenced by getTag(), and mvaValue().

200  {
201 
202  // Try to cast the particle into a reco particle.
203  // This should work for both reco and pat.
204  const edm::Ptr<reco::GsfElectron> eleRecoPtr = ( edm::Ptr<reco::GsfElectron> )particle;
205  if( eleRecoPtr.get() == nullptr ) {
206  throw cms::Exception("MVA failure: ")
207  << " given particle is expected to be reco::GsfElectron or pat::Electron," << std::endl
208  << " but appears to be neither" << std::endl;
209  }
210  return findCategory(eleRecoPtr.get());
211 }
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:159
#define nullptr
int findCategory(const edm::Ptr< reco::Candidate > &particle) const override
int ElectronMVAEstimatorRun2Fall17::findCategory ( const reco::GsfElectron particle) const

Definition at line 213 of file ElectronMVAEstimatorRun2Fall17.cc.

References funct::abs(), CAT_EB1_PTHig, CAT_EB1_PTLow, CAT_EB2_PTHig, CAT_EB2_PTLow, CAT_EE_PTHig, CAT_EE_PTLow, ebeeSplit_, ebSplit_, PVValHelper::eta, fillMVAVariables(), EnergyCorrector::pt, reco::LeafCandidate::pt(), ptSplit_, reco::GsfElectron::superCluster(), and UNDEFINED.

213  {
214  float pt = eleRecoPtr->pt();
215  float eta = eleRecoPtr->superCluster()->eta();
216  float absEta = std::abs(eta);
217 
218  //
219  // Determine the category
220  //
221  int iCategory = UNDEFINED;
222 
223  if (pt < ptSplit_ && absEta < ebSplit_) {
224  iCategory = CAT_EB1_PTLow;
225  }
226 
227  else if (pt < ptSplit_ && absEta >= ebSplit_ && absEta < ebeeSplit_) {
228  iCategory = CAT_EB2_PTLow;
229  }
230 
231  else if (pt < ptSplit_ && absEta >= ebeeSplit_) {
232  iCategory = CAT_EE_PTLow;
233  }
234 
235  else if (pt >= ptSplit_ && absEta < ebSplit_) {
236  iCategory = CAT_EB1_PTHig;
237  }
238 
239  else if (pt >= ptSplit_ && absEta >= ebSplit_ && absEta < ebeeSplit_) {
240  iCategory = CAT_EB2_PTHig;
241  }
242 
243  else if (pt >= ptSplit_ && absEta >= ebeeSplit_) {
244  iCategory = CAT_EE_PTHig;
245  }
246 
247  return iCategory;
248 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const std::string& ElectronMVAEstimatorRun2Fall17::getName ( void  ) const
inlinefinalvirtual

Implements AnyMVAEstimatorRun2Base.

Definition at line 48 of file ElectronMVAEstimatorRun2Fall17.h.

References name_.

Referenced by plotting.Plot::draw().

48 { return name_; }
int ElectronMVAEstimatorRun2Fall17::getNCategories ( ) const
inlineoverridevirtual

Implements AnyMVAEstimatorRun2Base.

Definition at line 47 of file ElectronMVAEstimatorRun2Fall17.h.

References nCategories_.

const std::string& ElectronMVAEstimatorRun2Fall17::getTag ( ) const
inlinefinalvirtual
void ElectronMVAEstimatorRun2Fall17::init ( const std::vector< std::string > &  weightFileNames)

Definition at line 57 of file ElectronMVAEstimatorRun2Fall17.cc.

References GBRForestTools::createGBRForest(), Exception, gbrForests_, mps_fire::i, nCategories_, and electrons_cff::weightFile.

Referenced by ElectronMVAEstimatorRun2Fall17().

57  {
58 
59  // Initialize GBRForests
60  if( (int)(weightFileNames.size()) != nCategories_ )
61  throw cms::Exception("MVA config failure: ")
62  << "wrong number of weightfiles" << std::endl;
63 
64  gbrForests_.clear();
65  // Create a TMVA reader object for each category
66  for(int i=0; i<nCategories_; i++){
67 
68  // Use unique_ptr so that all readers are properly cleaned up
69  // when the vector clear() is called in the destructor
70 
73 
74  }
75 
76 }
static std::unique_ptr< const GBRForest > createGBRForest(const std::string &weightFile)
std::vector< std::unique_ptr< const GBRForest > > gbrForests_
float ElectronMVAEstimatorRun2Fall17::mvaValue ( const edm::Ptr< reco::Candidate > &  particle,
const edm::Event iEvent 
) const
overridevirtual

Implements AnyMVAEstimatorRun2Base.

Definition at line 128 of file ElectronMVAEstimatorRun2Fall17.cc.

References Exception, fillMVAVariables(), findCategory(), edm::Ptr< T >::get(), and nullptr.

Referenced by mvaValue(), and setConsumes().

128  {
129  // Try to cast the particle into a reco particle.
130  // This should work for both reco and pat.
131  const edm::Ptr<reco::GsfElectron> eleRecoPtr = ( edm::Ptr<reco::GsfElectron> )particle;
132  if( eleRecoPtr.get() == nullptr ) {
133  throw cms::Exception("MVA failure: ")
134  << " given particle is expected to be reco::GsfElectron or pat::Electron," << std::endl
135  << " but appears to be neither" << std::endl;
136  }
137 
138  const int iCategory = findCategory( eleRecoPtr.get() );
139  const std::vector<float> vars = fillMVAVariables( particle, iEvent );
140  return mvaValue(iCategory, vars);
141 }
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:159
#define nullptr
float mvaValue(const edm::Ptr< reco::Candidate > &particle, const edm::Event &) const override
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
float ElectronMVAEstimatorRun2Fall17::mvaValue ( const reco::GsfElectron particle,
const edm::EventBase iEvent 
) const

Definition at line 144 of file ElectronMVAEstimatorRun2Fall17.cc.

References ecalDrivenElectronSeedsParameters_cff::beamSpot, beamSpotLabel_, conversions_cfi::conversions, conversionsLabelAOD_, fillMVAVariables(), findCategory(), edm::EventBase::getByLabel(), mvaValue(), edm::Handle< T >::product(), rho, and rhoLabel_.

144  {
148  iEvent.getByLabel(conversionsLabelAOD_, conversions);
149  iEvent.getByLabel(beamSpotLabel_, beamSpot);
150  iEvent.getByLabel(rhoLabel_, rho);
151  const int iCategory = findCategory( particle );
152  const std::vector<float> vars = fillMVAVariables( particle, conversions, beamSpot.product(), rho );
153  return mvaValue(iCategory, vars);
154 }
float mvaValue(const edm::Ptr< reco::Candidate > &particle, const edm::Event &) const override
T const * product() const
Definition: Handle.h:81
bool getByLabel(InputTag const &, Handle< T > &) const
Definition: EventBase.h:94
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
float ElectronMVAEstimatorRun2Fall17::mvaValue ( const int  iCategory,
const std::vector< float > &  vars 
) const

Definition at line 157 of file ElectronMVAEstimatorRun2Fall17.cc.

References gather_cfg::cout, debug_, gbrForests_, methodName_, mps_fire::result, and withIso_.

157  {
158  const float result = gbrForests_.at(iCategory)->GetClassifier(vars.data());
159 
160  if(debug_) {
161  std::cout << " *** Inside the class methodName_ " << methodName_ << std::endl;
162  std::cout << " bin " << iCategory << std::endl
163  << " see " << vars[0] << std::endl
164  << " spp " << vars[1] << std::endl
165  << " circularity " << vars[2] << std::endl
166  << " r9 " << vars[3] << std::endl
167  << " etawidth " << vars[4] << std::endl
168  << " phiwidth " << vars[5] << std::endl
169  << " hoe " << vars[6] << std::endl
170  << " kfhits " << vars[7] << std::endl
171  << " kfchi2 " << vars[8] << std::endl
172  << " gsfchi2 " << vars[9] << std::endl
173  << " fbrem " << vars[10] << std::endl
174  << " gsfhits " << vars[11] << std::endl
175  << " expectedMissingInnerHits " << vars[12] << std::endl
176  << " convVtxFitProbability " << vars[13] << std::endl
177  << " eop " << vars[14] << std::endl
178  << " eleeopout " << vars[15] << std::endl
179  << " oneOverEminusOneOverP " << vars[16] << std::endl
180  << " deta " << vars[17] << std::endl
181  << " dphi " << vars[18] << std::endl
182  << " detacalo " << vars[19] << std::endl;
183  if (withIso_) {
184  std::cout << " ele_pfPhotonIso " << vars[20] << std::endl
185  << " ele_pfChargedHadIso " << vars[21] << std::endl
186  << " ele_pfNeutralHadIso " << vars[22] << std::endl
187  << " rho " << vars[23] << std::endl
188  << " preShowerOverRaw " << vars[24] << std::endl;
189  }
190  else {
191  std::cout << " rho " << vars[20] << std::endl
192  << " preShowerOverRaw " << vars[21] << std::endl;
193  }
194  std::cout << " ### MVA " << result << std::endl << std::endl;
195  }
196 
197  return result;
198 }
std::vector< std::unique_ptr< const GBRForest > > gbrForests_
void ElectronMVAEstimatorRun2Fall17::setClips ( const std::vector< double > &  clipsLowerValues,
const std::vector< double > &  clipsUpperValues 
)

Definition at line 78 of file ElectronMVAEstimatorRun2Fall17.cc.

References clip(), clipsLower_, clipsUpper_, objects.autophobj::float, mps_fire::i, edm::isFinite(), and ~ElectronMVAEstimatorRun2Fall17().

Referenced by ElectronMVAEstimatorRun2Fall17().

78  {
79 
80  // Set up the variable clipping intructions
81  unsigned int i = 0;
82  for(auto const& value: clipsLowerValues) {
83  if (edm::isFinite(value)) {
84  Clip clip = {i, false, (float)value};
85  clipsLower_.push_back(clip);
86  }
87  ++i;
88  }
89 
90  i = 0;
91  for(auto const& value: clipsUpperValues) {
92  if (edm::isFinite(value)) {
93  Clip clip = {i, true, (float)value};
94  clipsUpper_.push_back(clip);
95  }
96  ++i;
97  }
98 
99 }
T clip(const T &n, const T &lower, const T &upper)
bool isFinite(T x)
Definition: value.py:1
void ElectronMVAEstimatorRun2Fall17::setConsumes ( edm::ConsumesCollector &&  cc) const
finalvirtual

Reimplemented from AnyMVAEstimatorRun2Base.

Definition at line 105 of file ElectronMVAEstimatorRun2Fall17.cc.

References beamSpotLabel_, conversionsLabelAOD_, conversionsLabelMiniAOD_, mvaValue(), and rhoLabel_.

Referenced by getTag().

105  {
106 
107  // All tokens for event content needed by this MVA
108 
109  // Beam spot (same for AOD and miniAOD)
111  // Conversions collection (different names in AOD and miniAOD)
114  // Event-by-event pileup estimate rho
115  cc.consumes<double>(rhoLabel_);
116 
118  //beamSpotToken_ = cc.consumes<reco::BeamSpot>(beamSpotLabel_);
120  //conversionsTokenAOD_ = cc.mayConsume<reco::ConversionCollection>(conversionsLabelAOD_);
121  //conversionsTokenMiniAOD_ = cc.mayConsume<reco::ConversionCollection>(conversionsLabelMiniAOD_);
123  //rhoToken_ = cc.consumes<double>(rhoLabel_);
124 
125 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
std::vector< Conversion > ConversionCollection
collectin of Conversion objects
Definition: ConversionFwd.h:9

Member Data Documentation

const edm::InputTag ElectronMVAEstimatorRun2Fall17::beamSpotLabel_
protected

Definition at line 108 of file ElectronMVAEstimatorRun2Fall17.h.

Referenced by fillMVAVariables(), mvaValue(), and setConsumes().

std::vector<Clip> ElectronMVAEstimatorRun2Fall17::clipsLower_
protected

Definition at line 125 of file ElectronMVAEstimatorRun2Fall17.h.

Referenced by constrainMVAVariables(), and setClips().

std::vector<Clip> ElectronMVAEstimatorRun2Fall17::clipsUpper_
protected

Definition at line 126 of file ElectronMVAEstimatorRun2Fall17.h.

Referenced by constrainMVAVariables(), and setClips().

const edm::InputTag ElectronMVAEstimatorRun2Fall17::conversionsLabelAOD_
protected

Definition at line 109 of file ElectronMVAEstimatorRun2Fall17.h.

Referenced by fillMVAVariables(), mvaValue(), and setConsumes().

const edm::InputTag ElectronMVAEstimatorRun2Fall17::conversionsLabelMiniAOD_
protected

Definition at line 110 of file ElectronMVAEstimatorRun2Fall17.h.

Referenced by fillMVAVariables(), and setConsumes().

bool ElectronMVAEstimatorRun2Fall17::debug_
protected

Definition at line 130 of file ElectronMVAEstimatorRun2Fall17.h.

Referenced by ElectronMVAEstimatorRun2Fall17(), and mvaValue().

double ElectronMVAEstimatorRun2Fall17::ebeeSplit_
protected

Definition at line 120 of file ElectronMVAEstimatorRun2Fall17.h.

Referenced by findCategory().

double ElectronMVAEstimatorRun2Fall17::ebSplit_
protected

Definition at line 119 of file ElectronMVAEstimatorRun2Fall17.h.

Referenced by findCategory().

std::vector< std::unique_ptr<const GBRForest> > ElectronMVAEstimatorRun2Fall17::gbrForests_
protected

Definition at line 100 of file ElectronMVAEstimatorRun2Fall17.h.

Referenced by init(), and mvaValue().

const std::string ElectronMVAEstimatorRun2Fall17::methodName_
protected

Definition at line 102 of file ElectronMVAEstimatorRun2Fall17.h.

Referenced by mvaValue().

const std::string ElectronMVAEstimatorRun2Fall17::name_
protected

Definition at line 97 of file ElectronMVAEstimatorRun2Fall17.h.

Referenced by getName().

const int ElectronMVAEstimatorRun2Fall17::nCategories_ = 6
protected

Definition at line 76 of file ElectronMVAEstimatorRun2Fall17.h.

Referenced by getNCategories(), and init().

const int ElectronMVAEstimatorRun2Fall17::nVar_ = 22
protected

Definition at line 77 of file ElectronMVAEstimatorRun2Fall17.h.

double ElectronMVAEstimatorRun2Fall17::ptSplit_
protected

Definition at line 118 of file ElectronMVAEstimatorRun2Fall17.h.

Referenced by findCategory().

const edm::InputTag ElectronMVAEstimatorRun2Fall17::rhoLabel_
protected

Definition at line 111 of file ElectronMVAEstimatorRun2Fall17.h.

Referenced by fillMVAVariables(), mvaValue(), and setConsumes().

const std::string ElectronMVAEstimatorRun2Fall17::tag_
protected

Definition at line 91 of file ElectronMVAEstimatorRun2Fall17.h.

Referenced by getTag().

std::vector<std::string> ElectronMVAEstimatorRun2Fall17::varNames_
protected

Definition at line 122 of file ElectronMVAEstimatorRun2Fall17.h.

bool ElectronMVAEstimatorRun2Fall17::withIso_
protected