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 bool absTrackClusterMatching_
 
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")),
17 {
18 
19  const std::vector <std::string> weightFileNames
20  = conf.getParameter<std::vector<std::string> >("weightFileNames");
21 
22  std::vector<double> clipsLowerValues = conf.getParameter<std::vector<double>>("clipLower");
23  std::vector<double> clipsUpperValues = conf.getParameter<std::vector<double>>("clipUpper");
24 
25  // Initialize GBRForests and and clipping instructions
26  init(weightFileNames);
27  setClips(clipsLowerValues, clipsUpperValues);
28 
29  withIso_ = withIso;
30  debug_ = conf.getUntrackedParameter<bool>("debug", false);
31 
32 }
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 104 of file ElectronMVAEstimatorRun2Fall17.cc.

Referenced by setClips().

104  {
105 }
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 34 of file ElectronMVAEstimatorRun2Fall17.cc.

References debug, debug_, and withIso_.

36  :
38  tag_ (mvaTag),
39  name_ (mvaName),
40  methodName_ ("BDTG method"),
41  beamSpotLabel_ (edm::InputTag(beamspotTag)),
42  conversionsLabelAOD_ (edm::InputTag(conversionsTag)),
44  rhoLabel_ (edm::InputTag("fixedGridRhoFastjetAll")),
45  ptSplit_ (ptSplit),
46  ebSplit_ (ebSplit),
49 {
50 
51  // Set if this is the ID with or without PF isolations
52  withIso_ = withIso;
53 
54  // Set debug flag
55  debug_ = debug;
56 
57 }
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 546 of file ElectronMVAEstimatorRun2Fall17.cc.

References clip(), clipsLower_, and clipsUpper_.

Referenced by fillMVAVariables(), and getTag().

546  {
547 
548  // Check that variables do not have crazy values
549 
550  for(auto const& clip: clipsLower_) {
551  if ( vars[clip.varIdx] < clip.value ) {
552  vars[clip.varIdx] = clip.value;
553  }
554  }
555 
556  for(auto const& clip: clipsUpper_) {
557  if ( vars[clip.varIdx] > clip.value ) {
558  vars[clip.varIdx] = clip.value;
559  }
560  }
561 
562 }
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 254 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().

254  {
255 
256  //
257  // Declare all value maps corresponding to the products we defined earlier
258  //
259  edm::Handle<double> theRho;
260  edm::Handle<reco::BeamSpot> theBeamSpot;
262 
263  iEvent.getByLabel(rhoLabel_, theRho);
264 
265  // Get data needed for conversion rejection
266  iEvent.getByLabel(beamSpotLabel_, theBeamSpot);
267 
268  // Conversions in miniAOD and AOD have different names,
269  // but the same type, so we use the same handle with different tokens.
270  iEvent.getByLabel(conversionsLabelAOD_, conversions);
271  if( !conversions.isValid() ) {
272  iEvent.getByLabel(conversionsLabelMiniAOD_, conversions);
273  }
274 
275  // Make sure everything is retrieved successfully
276  if(! (theBeamSpot.isValid()
277  && conversions.isValid() )
278  ) {
279  throw cms::Exception("MVA failure: ")
280  << "Failed to retrieve event content needed for this MVA"
281  << std::endl
282  << "Check python MVA configuration file."
283  << std::endl;
284  }
285 
286  // Try to cast the particle into a reco particle.
287  // This should work for both reco and pat.
288  const edm::Ptr<reco::GsfElectron> eleRecoPtr = ( edm::Ptr<reco::GsfElectron> )particle;
289  if( eleRecoPtr.get() == nullptr ) {
290  throw cms::Exception("MVA failure: ")
291  << " given particle is expected to be reco::GsfElectron or pat::Electron," << std::endl
292  << " but appears to be neither" << std::endl;
293  }
294 
295  return fillMVAVariables(eleRecoPtr.get(), conversions, theBeamSpot.product(), theRho);
296 }
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:464
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 300 of file ElectronMVAEstimatorRun2Fall17.cc.

References funct::abs(), absTrackClusterMatching_, 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(), findCategory(), 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(), tag_, reco::GsfElectron::trackMomentumAtVtx(), badGlobalMuonTaggersAOD_cff::vtx, and withIso_.

300  {
301 
302  const int iCategory = findCategory( eleRecoPtr );
303 
304  // Both pat and reco particles have exactly the same accessors, so we use a reco ptr
305  // throughout the code, with a single exception as of this writing, handled separately below.
306  auto superCluster = eleRecoPtr->superCluster();
307 
308  // Pure ECAL -> shower shapes
309  float see = eleRecoPtr->full5x5_sigmaIetaIeta();
310  float spp = eleRecoPtr->full5x5_sigmaIphiIphi();
311  float circularity = 1. - eleRecoPtr->full5x5_e1x5() / eleRecoPtr->full5x5_e5x5();
312  float r9 = eleRecoPtr->full5x5_r9();
313  float etawidth = superCluster->etaWidth();
314  float phiwidth = superCluster->phiWidth();
315  float hoe = eleRecoPtr->full5x5_hcalOverEcal(); //hadronicOverEm();
316  // Endcap only variables
317  float preShowerOverRaw = superCluster->preshowerEnergy() / superCluster->rawEnergy();
318 
319  // To get to CTF track information in pat::Electron, we have to have the pointer
320  // to pat::Electron, it is not accessible from the pointer to reco::GsfElectron.
321  // This behavior is reported and is expected to change in the future (post-7.4.5 some time).
322  bool validKF= false;
323  reco::TrackRef myTrackRef = eleRecoPtr->closestCtfTrackRef();
324  const pat::Electron * elePatPtr = dynamic_cast<const pat::Electron *>(eleRecoPtr);
325  // Check if this is really a pat::Electron, and if yes, get the track ref from this new
326  // pointer instead
327  if( elePatPtr != nullptr ) {
328  myTrackRef = elePatPtr->closestCtfTrackRef();
329  }
330  validKF = (myTrackRef.isAvailable() && (myTrackRef.isNonnull()) );
331 
332  //Pure tracking variables
333  float kfhits = (validKF) ? myTrackRef->hitPattern().trackerLayersWithMeasurement() : -1. ;
334  float kfchi2 = (validKF) ? myTrackRef->normalizedChi2() : 0;
335  float gsfchi2 = eleRecoPtr->gsfTrack()->normalizedChi2();
336 
337  // Energy matching
338  float fbrem = eleRecoPtr->fbrem();
339 
340  float gsfhits = eleRecoPtr->gsfTrack()->hitPattern().trackerLayersWithMeasurement();
341  float expectedMissingInnerHits = eleRecoPtr->gsfTrack()
342  ->hitPattern().numberOfLostHits(reco::HitPattern::MISSING_INNER_HITS);
343 
345  conversions,
346  theBeamSpot->position());
347  float convVtxFitProbability = -1.;
348  if(!convRef.isNull()) {
349  const reco::Vertex &vtx = convRef.get()->conversionVertex();
350  if (vtx.isValid()) {
351  convVtxFitProbability = (float)TMath::Prob( vtx.chi2(), vtx.ndof());
352  }
353  }
354 
355  float eop = eleRecoPtr->eSuperClusterOverP();
356  float eleeopout = eleRecoPtr->eEleClusterOverPout();
357  float pAtVertex = eleRecoPtr->trackMomentumAtVtx().R();
358  float oneOverEminusOneOverP = (1.0/eleRecoPtr->ecalEnergy()) - (1.0 / pAtVertex );
359 
360  // Geometrical matchings
361  float deta = eleRecoPtr->deltaEtaSuperClusterTrackAtVtx();
362  float dphi = eleRecoPtr->deltaPhiSuperClusterTrackAtVtx();
363  float detacalo = eleRecoPtr->deltaEtaSeedClusterTrackAtCalo();
364 
365  // Required by V2 ID
367  deta = std::abs(deta);
368  dphi = std::abs(dphi);
369  detacalo = std::abs(detacalo);
370  }
371 
372  if(tag_ == "V2" && withIso_)
373  {
374 
375  // Isolation variables
376  float pfChargedHadIso = (eleRecoPtr->pfIsolationVariables()).sumChargedHadronPt ; //chargedHadronIso();
377  float pfNeutralHadIso = (eleRecoPtr->pfIsolationVariables()).sumNeutralHadronEt ; //neutralHadronIso();
378  float pfPhotonIso = (eleRecoPtr->pfIsolationVariables()).sumPhotonEt; //photonIso();
379 
380  if ((iCategory + 1) % 3 == 0) {
381  std::vector<float> vars = packMVAVariables(
382  see, // 0
383  spp, // 1
384  circularity,
385  r9,
386  etawidth,
387  phiwidth, // 5
388  hoe,
389  //Pure tracking variables
390  kfhits,
391  kfchi2,
392  gsfchi2, // 9
393  // Energy matching
394  fbrem,
395  gsfhits,
396  expectedMissingInnerHits,
397  convVtxFitProbability, // 13
398  eop,
399  eleeopout, // 15
400  oneOverEminusOneOverP,
401  // Geometrical matchings
402  deta, // 17
403  dphi,
404  detacalo,
405  // Pileup
406  (float)*rho,
407  // Endcap only
408  preShowerOverRaw, // 24
409  // Isolation variables
410  pfPhotonIso,
411  pfChargedHadIso,
412  pfNeutralHadIso
413  );
414  constrainMVAVariables(vars);
415  return vars;
416  } else {
417  std::vector<float> vars = packMVAVariables(
418  see, // 0
419  spp, // 1
420  circularity,
421  r9,
422  etawidth,
423  phiwidth, // 5
424  hoe,
425  //Pure tracking variables
426  kfhits,
427  kfchi2,
428  gsfchi2, // 9
429  // Energy matching
430  fbrem,
431  gsfhits,
432  expectedMissingInnerHits,
433  convVtxFitProbability, // 13
434  eop,
435  eleeopout, // 15
436  oneOverEminusOneOverP,
437  // Geometrical matchings
438  deta, // 17
439  dphi,
440  detacalo,
441  // Pileup
442  (float)*rho,
443  // Isolation variables
444  pfPhotonIso,
445  pfChargedHadIso,
446  pfNeutralHadIso
447  );
448  constrainMVAVariables(vars);
449  return vars;
450  }
451  }
452  else if(withIso_)
453  {
454 
455  // Isolation variables
456  float pfChargedHadIso = (eleRecoPtr->pfIsolationVariables()).sumChargedHadronPt ; //chargedHadronIso();
457  float pfNeutralHadIso = (eleRecoPtr->pfIsolationVariables()).sumNeutralHadronEt ; //neutralHadronIso();
458  float pfPhotonIso = (eleRecoPtr->pfIsolationVariables()).sumPhotonEt; //photonIso();
459 
460  /*
461  * Packing variables for the MVA evaluation.
462  * CAREFUL: It is critical that all the variables that are packed into “vars” are
463  * exactly in the order they are found in the weight files
464  */
465  std::vector<float> vars = packMVAVariables(
466  see, // 0
467  spp, // 1
468  circularity,
469  r9,
470  etawidth,
471  phiwidth, // 5
472  hoe,
473  //Pure tracking variables
474  kfhits,
475  kfchi2,
476  gsfchi2, // 9
477  // Energy matching
478  fbrem,
479  gsfhits,
480  expectedMissingInnerHits,
481  convVtxFitProbability, // 13
482  eop,
483  eleeopout, // 15
484  oneOverEminusOneOverP,
485  // Geometrical matchings
486  deta, // 17
487  dphi,
488  detacalo,
489  // Isolation variables
490  pfPhotonIso,
491  pfChargedHadIso,
492  pfNeutralHadIso,
493  // Pileup
494  (float)*rho,
495 
496  // Endcap only variables NOTE: we don't need
497  // to check if we are actually in the endcap
498  // or not, as it is the last variable in the
499  // vector and it will be ignored by the
500  // GBRForest for the barrel.
501  //
502  // The GBRForest classification just needs an
503  // array with the input variables in the
504  // right order, what comes after doesn't
505  // matter.
506  preShowerOverRaw // 24
507  );
508 
509  constrainMVAVariables(vars);
510 
511  return vars;
512  }
513  else
514  {
515  std::vector<float> vars = packMVAVariables(
516  see, // 0
517  spp, // 1
518  circularity,
519  r9,
520  etawidth,
521  phiwidth, // 5
522  hoe,
523  kfhits,
524  kfchi2,
525  gsfchi2, // 9
526  fbrem,
527  gsfhits,
528  expectedMissingInnerHits,
529  convVtxFitProbability, // 13
530  eop,
531  eleeopout, // 15
532  oneOverEminusOneOverP,
533  deta, // 17
534  dphi,
535  detacalo,
536  (float)*rho,
537  preShowerOverRaw // 21
538  );
539 
540  constrainMVAVariables(vars);
541 
542  return vars;
543  }
544 }
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
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
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...
int findCategory(const edm::Ptr< reco::Candidate > &particle) const override
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 202 of file ElectronMVAEstimatorRun2Fall17.cc.

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

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

202  {
203 
204  // Try to cast the particle into a reco particle.
205  // This should work for both reco and pat.
206  const edm::Ptr<reco::GsfElectron> eleRecoPtr = ( edm::Ptr<reco::GsfElectron> )particle;
207  if( eleRecoPtr.get() == nullptr ) {
208  throw cms::Exception("MVA failure: ")
209  << " given particle is expected to be reco::GsfElectron or pat::Electron," << std::endl
210  << " but appears to be neither" << std::endl;
211  }
212  return findCategory(eleRecoPtr.get());
213 }
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 215 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.

215  {
216  float pt = eleRecoPtr->pt();
217  float eta = eleRecoPtr->superCluster()->eta();
218  float absEta = std::abs(eta);
219 
220  //
221  // Determine the category
222  //
223  int iCategory = UNDEFINED;
224 
225  if (pt < ptSplit_ && absEta < ebSplit_) {
226  iCategory = CAT_EB1_PTLow;
227  }
228 
229  else if (pt < ptSplit_ && absEta >= ebSplit_ && absEta < ebeeSplit_) {
230  iCategory = CAT_EB2_PTLow;
231  }
232 
233  else if (pt < ptSplit_ && absEta >= ebeeSplit_) {
234  iCategory = CAT_EE_PTLow;
235  }
236 
237  else if (pt >= ptSplit_ && absEta < ebSplit_) {
238  iCategory = CAT_EB1_PTHig;
239  }
240 
241  else if (pt >= ptSplit_ && absEta >= ebSplit_ && absEta < ebeeSplit_) {
242  iCategory = CAT_EB2_PTHig;
243  }
244 
245  else if (pt >= ptSplit_ && absEta >= ebeeSplit_) {
246  iCategory = CAT_EE_PTHig;
247  }
248 
249  return iCategory;
250 }
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 ( void  ) const
inlinefinalvirtual
void ElectronMVAEstimatorRun2Fall17::init ( const std::vector< std::string > &  weightFileNames)

Definition at line 59 of file ElectronMVAEstimatorRun2Fall17.cc.

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

Referenced by ElectronMVAEstimatorRun2Fall17().

59  {
60 
61  // Initialize GBRForests
62  if( (int)(weightFileNames.size()) != nCategories_ )
63  throw cms::Exception("MVA config failure: ")
64  << "wrong number of weightfiles" << std::endl;
65 
66  gbrForests_.clear();
67  // Create a TMVA reader object for each category
68  for(int i=0; i<nCategories_; i++){
69 
70  // Use unique_ptr so that all readers are properly cleaned up
71  // when the vector clear() is called in the destructor
72 
75 
76  }
77 
78 }
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 130 of file ElectronMVAEstimatorRun2Fall17.cc.

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

Referenced by mvaValue(), and setConsumes().

130  {
131  // Try to cast the particle into a reco particle.
132  // This should work for both reco and pat.
133  const edm::Ptr<reco::GsfElectron> eleRecoPtr = ( edm::Ptr<reco::GsfElectron> )particle;
134  if( eleRecoPtr.get() == nullptr ) {
135  throw cms::Exception("MVA failure: ")
136  << " given particle is expected to be reco::GsfElectron or pat::Electron," << std::endl
137  << " but appears to be neither" << std::endl;
138  }
139 
140  const int iCategory = findCategory( eleRecoPtr.get() );
141  const std::vector<float> vars = fillMVAVariables( particle, iEvent );
142  return mvaValue(iCategory, vars);
143 }
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 146 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_.

146  {
150  iEvent.getByLabel(conversionsLabelAOD_, conversions);
151  iEvent.getByLabel(beamSpotLabel_, beamSpot);
152  iEvent.getByLabel(rhoLabel_, rho);
153  const int iCategory = findCategory( particle );
154  const std::vector<float> vars = fillMVAVariables( particle, conversions, beamSpot.product(), rho );
155  return mvaValue(iCategory, vars);
156 }
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 159 of file ElectronMVAEstimatorRun2Fall17.cc.

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

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

Definition at line 80 of file ElectronMVAEstimatorRun2Fall17.cc.

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

Referenced by ElectronMVAEstimatorRun2Fall17().

80  {
81 
82  // Set up the variable clipping intructions
83  unsigned int i = 0;
84  for(auto const& value: clipsLowerValues) {
85  if (edm::isFinite(value)) {
86  Clip clip = {i, false, (float)value};
87  clipsLower_.push_back(clip);
88  }
89  ++i;
90  }
91 
92  i = 0;
93  for(auto const& value: clipsUpperValues) {
94  if (edm::isFinite(value)) {
95  Clip clip = {i, true, (float)value};
96  clipsUpper_.push_back(clip);
97  }
98  ++i;
99  }
100 
101 }
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 107 of file ElectronMVAEstimatorRun2Fall17.cc.

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

Referenced by getTag().

107  {
108 
109  // All tokens for event content needed by this MVA
110 
111  // Beam spot (same for AOD and miniAOD)
113  // Conversions collection (different names in AOD and miniAOD)
116  // Event-by-event pileup estimate rho
117  cc.consumes<double>(rhoLabel_);
118 
120  //beamSpotToken_ = cc.consumes<reco::BeamSpot>(beamSpotLabel_);
122  //conversionsTokenAOD_ = cc.mayConsume<reco::ConversionCollection>(conversionsLabelAOD_);
123  //conversionsTokenMiniAOD_ = cc.mayConsume<reco::ConversionCollection>(conversionsLabelMiniAOD_);
125  //rhoToken_ = cc.consumes<double>(rhoLabel_);
126 
127 }
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 bool ElectronMVAEstimatorRun2Fall17::absTrackClusterMatching_
protected

Definition at line 132 of file ElectronMVAEstimatorRun2Fall17.h.

Referenced by fillMVAVariables().

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 fillMVAVariables(), and getTag().

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

Definition at line 122 of file ElectronMVAEstimatorRun2Fall17.h.

bool ElectronMVAEstimatorRun2Fall17::withIso_
protected