CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Public Attributes | Private Attributes
ElectronMVAEstimatorRun2Spring16GeneralPurpose Class Reference

#include <ElectronMVAEstimatorRun2Spring16GeneralPurpose.h>

Inheritance diagram for ElectronMVAEstimatorRun2Spring16GeneralPurpose:
AnyMVAEstimatorRun2Base

Classes

struct  AllVariables
 

Public Types

enum  mvaCategories { UNDEFINED = -1, CAT_EB1_PT10plus = 0, CAT_EB2_PT10plus = 1, CAT_EE_PT10plus = 2 }
 

Public Member Functions

void constrainMVAVariables (AllVariables &) const
 
std::unique_ptr< const GBRForestcreateSingleReader (const int iCategory, const edm::FileInPath &weightFile)
 
 ElectronMVAEstimatorRun2Spring16GeneralPurpose (const edm::ParameterSet &conf)
 
 ElectronMVAEstimatorRun2Spring16GeneralPurpose ()
 
 ElectronMVAEstimatorRun2Spring16GeneralPurpose (const std::string &mvaTag, const std::string &conversionsTag="reducedEgamma:reducedConversions", const std::string &beamspotTag="offlineBeamSpot")
 
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
 
int findCategory (const edm::Ptr< reco::Candidate > &particle) const override
 
int findCategory (const reco::GsfElectron *particle) const
 
virtual const std::string & getName () const override final
 
virtual int getNCategories () const override
 
virtual const std::string & getTag () const override final
 
void init (const std::vector< std::string > weightFileNames)
 
bool isEndcapCategory (int category) const
 
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 setConsumes (edm::ConsumesCollector &&) const override final
 
 ~ElectronMVAEstimatorRun2Spring16GeneralPurpose ()
 
- 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 ()
 

Public Attributes

const int nCategories = 3
 
- Public Attributes inherited from AnyMVAEstimatorRun2Base
const edm::ParameterSet _conf
 

Private Attributes

AllVariables allMVAVars_
 
const edm::InputTag beamSpotLabel_
 
const edm::InputTag conversionsLabelAOD_
 
const edm::InputTag conversionsLabelMiniAOD_
 
std::vector< std::unique_ptr< const GBRForest > > gbrForest_s
 
const std::string MethodName_
 
const std::string name_ = "ElectronMVAEstimatorRun2Spring16GeneralPurpose"
 
const std::string tag_
 

Detailed Description

Definition at line 22 of file ElectronMVAEstimatorRun2Spring16GeneralPurpose.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

ElectronMVAEstimatorRun2Spring16GeneralPurpose::ElectronMVAEstimatorRun2Spring16GeneralPurpose ( const edm::ParameterSet conf)

Definition at line 13 of file ElectronMVAEstimatorRun2Spring16GeneralPurpose.cc.

References edm::ParameterSet::getParameter(), init(), and mvaElectronID_PHYS14_PU20bx25_nonTrig_V1_cff::weightFileNames.

13  :
15  tag_(conf.getParameter<std::string>("mvaTag")),
16  MethodName_("BDTG method"),
17  beamSpotLabel_(conf.getParameter<edm::InputTag>("beamSpot")),
18  conversionsLabelAOD_(conf.getParameter<edm::InputTag>("conversionsAOD")),
19  conversionsLabelMiniAOD_(conf.getParameter<edm::InputTag>("conversionsMiniAOD")) {
20 
21  const std::vector <std::string> weightFileNames
22  = conf.getParameter<std::vector<std::string> >("weightFileNames");
23  init(weightFileNames);
24 }
T getParameter(std::string const &) const
void init(const std::vector< std::string > weightFileNames)
AnyMVAEstimatorRun2Base(const edm::ParameterSet &conf)
ElectronMVAEstimatorRun2Spring16GeneralPurpose::ElectronMVAEstimatorRun2Spring16GeneralPurpose ( )
ElectronMVAEstimatorRun2Spring16GeneralPurpose::ElectronMVAEstimatorRun2Spring16GeneralPurpose ( const std::string &  mvaTag,
const std::string &  conversionsTag = "reducedEgamma:reducedConversions",
const std::string &  beamspotTag = "offlineBeamSpot" 
)

Definition at line 48 of file ElectronMVAEstimatorRun2Spring16GeneralPurpose.cc.

References ~ElectronMVAEstimatorRun2Spring16GeneralPurpose().

ElectronMVAEstimatorRun2Spring16GeneralPurpose::~ElectronMVAEstimatorRun2Spring16GeneralPurpose ( )

Member Function Documentation

void ElectronMVAEstimatorRun2Spring16GeneralPurpose::constrainMVAVariables ( AllVariables allMVAVars) const

Definition at line 416 of file ElectronMVAEstimatorRun2Spring16GeneralPurpose.cc.

References ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::deta, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::detacalo, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::dphi, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::eleEoPout, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::EoP, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::fbrem, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::gsfchi2, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::kfchi2, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::OneMinusE1x5E5x5, and ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::R9.

Referenced by fillMVAVariables(), and getTag().

416  {
417 
418  // Check that variables do not have crazy values
419 
420  if(allMVAVars.fbrem < -1.)
421  allMVAVars.fbrem = -1.;
422 
423  allMVAVars.deta = fabs(allMVAVars.deta);
424  if(allMVAVars.deta > 0.06)
425  allMVAVars.deta = 0.06;
426 
427 
428  allMVAVars.dphi = fabs(allMVAVars.dphi);
429  if(allMVAVars.dphi > 0.6)
430  allMVAVars.dphi = 0.6;
431 
432 
433  if(allMVAVars.EoP > 20.)
434  allMVAVars.EoP = 20.;
435 
436  if(allMVAVars.eleEoPout > 20.)
437  allMVAVars.eleEoPout = 20.;
438 
439 
440  allMVAVars.detacalo = fabs(allMVAVars.detacalo);
441  if(allMVAVars.detacalo > 0.2)
442  allMVAVars.detacalo = 0.2;
443 
444  if(allMVAVars.OneMinusE1x5E5x5 < -1.)
445  allMVAVars.OneMinusE1x5E5x5 = -1;
446 
447  if(allMVAVars.OneMinusE1x5E5x5 > 2.)
448  allMVAVars.OneMinusE1x5E5x5 = 2.;
449 
450 
451  if(allMVAVars.R9 > 5)
452  allMVAVars.R9 = 5;
453 
454  if(allMVAVars.gsfchi2 > 200.)
455  allMVAVars.gsfchi2 = 200;
456 
457 
458  if(allMVAVars.kfchi2 > 10.)
459  allMVAVars.kfchi2 = 10.;
460 }
std::unique_ptr< const GBRForest > ElectronMVAEstimatorRun2Spring16GeneralPurpose::createSingleReader ( const int  iCategory,
const edm::FileInPath weightFile 
)

Definition at line 177 of file ElectronMVAEstimatorRun2Spring16GeneralPurpose.cc.

References allMVAVars_, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::convVtxFitProbability, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::deta, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::detacalo, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::dphi, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::eleEoPout, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::EoP, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::etawidth, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::expectedMissingInnerHits, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::fbrem, fillMVAVariables(), edm::FileInPath::fullPath(), ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::gsfchi2, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::gsfhits, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::HoE, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::IoEmIoP, isEndcapCategory(), ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::kfchi2, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::kfhits, MethodName_, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::OneMinusE1x5E5x5, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::phiwidth, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::PreShowerOverRaw, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::pt, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::R9, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::SCeta, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::see, and ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::spp.

Referenced by init(), and isEndcapCategory().

177  {
178 
179  //
180  // Create the reader
181  //
182  TMVA::Reader tmpTMVAReader( "!Color:Silent:!Error" );
183 
184  //
185  // Configure all variables and spectators. Note: the order and names
186  // must match what is found in the xml weights file!
187  //
188 
189  // Pure ECAL -> shower shapes
190  tmpTMVAReader.AddVariable("ele_oldsigmaietaieta", &allMVAVars_.see);
191  tmpTMVAReader.AddVariable("ele_oldsigmaiphiiphi", &allMVAVars_.spp);
192  tmpTMVAReader.AddVariable("ele_oldcircularity", &allMVAVars_.OneMinusE1x5E5x5);
193  tmpTMVAReader.AddVariable("ele_oldr9", &allMVAVars_.R9);
194  tmpTMVAReader.AddVariable("ele_scletawidth", &allMVAVars_.etawidth);
195  tmpTMVAReader.AddVariable("ele_sclphiwidth", &allMVAVars_.phiwidth);
196  tmpTMVAReader.AddVariable("ele_oldhe", &allMVAVars_.HoE);
197 
198  //Pure tracking variables
199  tmpTMVAReader.AddVariable("ele_kfhits", &allMVAVars_.kfhits);
200  tmpTMVAReader.AddVariable("ele_kfchi2", &allMVAVars_.kfchi2);
201  tmpTMVAReader.AddVariable("ele_gsfchi2", &allMVAVars_.gsfchi2);
202 
203  // Energy matching
204  tmpTMVAReader.AddVariable("ele_fbrem", &allMVAVars_.fbrem);
205 
206  tmpTMVAReader.AddVariable("ele_gsfhits", &allMVAVars_.gsfhits);
207  tmpTMVAReader.AddVariable("ele_expected_inner_hits", &allMVAVars_.expectedMissingInnerHits);
208  tmpTMVAReader.AddVariable("ele_conversionVertexFitProbability", &allMVAVars_.convVtxFitProbability);
209 
210  tmpTMVAReader.AddVariable("ele_ep", &allMVAVars_.EoP);
211  tmpTMVAReader.AddVariable("ele_eelepout", &allMVAVars_.eleEoPout);
212  tmpTMVAReader.AddVariable("ele_IoEmIop", &allMVAVars_.IoEmIoP);
213 
214  // Geometrical matchings
215  tmpTMVAReader.AddVariable("ele_deltaetain", &allMVAVars_.deta);
216  tmpTMVAReader.AddVariable("ele_deltaphiin", &allMVAVars_.dphi);
217  tmpTMVAReader.AddVariable("ele_deltaetaseed", &allMVAVars_.detacalo);
218 
219  tmpTMVAReader.AddVariable("ele_pt", &allMVAVars_.pt);
220  tmpTMVAReader.AddVariable("scl_eta", &allMVAVars_.SCeta);
221 
222  // Endcap only variables
223  if( isEndcapCategory(iCategory) )
224  tmpTMVAReader.AddVariable("ele_psEoverEraw", &allMVAVars_.PreShowerOverRaw);
225 
226  //
227  // Book the method and set up the weights file
228  //
229  tmpTMVAReader.BookMVA(MethodName_ , weightFile.fullPath());
230 
231  return std::unique_ptr<const GBRForest> ( new GBRForest( dynamic_cast<TMVA::MethodBDT*>( tmpTMVAReader.FindMVA(MethodName_) ) ) );
232 }
std::string fullPath() const
Definition: FileInPath.cc:184
std::vector< float > ElectronMVAEstimatorRun2Spring16GeneralPurpose::fillMVAVariables ( const edm::Ptr< reco::Candidate > &  particle,
const edm::Event iEvent 
) const
overridevirtual

Implements AnyMVAEstimatorRun2Base.

Definition at line 236 of file ElectronMVAEstimatorRun2Spring16GeneralPurpose.cc.

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

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

237  {
238 
239  //
240  // Declare all value maps corresponding to the products we defined earlier
241  //
242  edm::Handle<reco::BeamSpot> theBeamSpot;
244 
245  // Get data needed for conversion rejection
246  iEvent.getByLabel(beamSpotLabel_, theBeamSpot);
247 
248  // Conversions in miniAOD and AOD have different names,
249  // but the same type, so we use the same handle with different tokens.
250  iEvent.getByLabel(conversionsLabelAOD_, conversions);
251  if( !conversions.isValid() )
252  iEvent.getByLabel(conversionsLabelMiniAOD_, conversions);
253 
254  // Make sure everything is retrieved successfully
255  if(! (theBeamSpot.isValid()
256  && conversions.isValid() )
257  )
258  throw cms::Exception("MVA failure: ")
259  << "Failed to retrieve event content needed for this MVA"
260  << std::endl
261  << "Check python MVA configuration file."
262  << std::endl;
263 
264  // Try to cast the particle into a reco particle.
265  // This should work for both reco and pat.
266  const edm::Ptr<reco::GsfElectron> eleRecoPtr = ( edm::Ptr<reco::GsfElectron> )particle;
267  if( eleRecoPtr.get() == NULL )
268  throw cms::Exception("MVA failure: ")
269  << " given particle is expected to be reco::GsfElectron or pat::Electron," << std::endl
270  << " but appears to be neither" << std::endl;
271  return fillMVAVariables(eleRecoPtr.get(), conversions, theBeamSpot.product());
272 }
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:160
#define NULL
Definition: scimark2.h:8
std::vector< float > fillMVAVariables(const edm::Ptr< reco::Candidate > &particle, const edm::Event &) const override
bool isValid() const
Definition: HandleBase.h:74
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:416
T const * product() const
Definition: Handle.h:81
std::vector< float > ElectronMVAEstimatorRun2Spring16GeneralPurpose::fillMVAVariables ( const reco::GsfElectron particle,
const edm::Handle< reco::ConversionCollection conversions,
const reco::BeamSpot beamSpot 
) const

Definition at line 276 of file ElectronMVAEstimatorRun2Spring16GeneralPurpose.cc.

References funct::abs(), reco::Vertex::chi2(), pat::Electron::closestCtfTrackRef(), reco::GsfElectron::closestCtfTrackRef(), constexpr, constrainMVAVariables(), ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::convVtxFitProbability, reco::GsfElectron::deltaEtaSeedClusterTrackAtCalo(), reco::GsfElectron::deltaEtaSuperClusterTrackAtVtx(), reco::GsfElectron::deltaPhiSuperClusterTrackAtVtx(), ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::deta, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::detacalo, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::dphi, reco::GsfElectron::ecalEnergy(), reco::GsfElectron::eEleClusterOverPout(), ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::eleEoPout, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::EoP, reco::GsfElectron::eSuperClusterOverP(), ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::etawidth, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::expectedMissingInnerHits, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::fbrem, reco::GsfElectron::fbrem(), findCategory(), 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(), ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::gsfchi2, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::gsfhits, reco::GsfElectron::gsfTrack(), ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::HoE, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::IoEmIoP, edm::Ref< C, T, F >::isAvailable(), ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::isBarrel, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::isEndcap, isEndcapCategory(), edm::Ref< C, T, F >::isNonnull(), edm::Ref< C, T, F >::isNull(), reco::Vertex::isValid(), ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::kfchi2, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::kfhits, ConversionTools::matchedConversion(), reco::HitPattern::MISSING_INNER_HITS, eostools::move(), reco::Vertex::ndof(), NULL, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::OneMinusE1x5E5x5, AnyMVAEstimatorRun2Base::packMVAVariables(), ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::phiwidth, reco::BeamSpot::position(), ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::PreShowerOverRaw, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::pt, reco::LeafCandidate::pt(), ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::R9, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::SCeta, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::see, ElectronMVAEstimatorRun2Spring16GeneralPurpose::AllVariables::spp, reco::GsfElectron::superCluster(), reco::GsfElectron::trackMomentumAtVtx(), and badGlobalMuonTaggersAOD_cff::vtx.

277  {
278 
279 
280  // Both pat and reco particles have exactly the same accessors, so we use a reco ptr
281  // throughout the code, with a single exception as of this writing, handled separately below.
282  auto superCluster = eleRecoPtr->superCluster();
283 
284  AllVariables allMVAVars;
285 
286  // Pure ECAL -> shower shapes
287  allMVAVars.see = eleRecoPtr->full5x5_sigmaIetaIeta();
288  allMVAVars.spp = eleRecoPtr->full5x5_sigmaIphiIphi();
289  allMVAVars.OneMinusE1x5E5x5 = 1. - eleRecoPtr->full5x5_e1x5() / eleRecoPtr->full5x5_e5x5();
290  allMVAVars.R9 = eleRecoPtr->full5x5_r9();
291  allMVAVars.etawidth = superCluster->etaWidth();
292  allMVAVars.phiwidth = superCluster->phiWidth();
293  allMVAVars.HoE = eleRecoPtr->full5x5_hcalOverEcal(); //hadronicOverEm();
294  // Endcap only variables
295  allMVAVars.PreShowerOverRaw = superCluster->preshowerEnergy() / superCluster->rawEnergy();
296 
297  // To get to CTF track information in pat::Electron, we have to have the pointer
298  // to pat::Electron, it is not accessible from the pointer to reco::GsfElectron.
299  // This behavior is reported and is expected to change in the future (post-7.4.5 some time).
300  bool validKF= false;
301  reco::TrackRef myTrackRef = eleRecoPtr->closestCtfTrackRef();
302  const pat::Electron * elePatPtr = dynamic_cast<const pat::Electron *>(eleRecoPtr);
303  // Check if this is really a pat::Electron, and if yes, get the track ref from this new
304  // pointer instead
305  if( elePatPtr != NULL )
306  myTrackRef = elePatPtr->closestCtfTrackRef();
307  validKF = (myTrackRef.isAvailable() && (myTrackRef.isNonnull()) );
308 
309  //Pure tracking variables
310  allMVAVars.kfhits = (validKF) ? myTrackRef->hitPattern().trackerLayersWithMeasurement() : -1. ;
311  allMVAVars.kfchi2 = (validKF) ? myTrackRef->normalizedChi2() : 0;
312  allMVAVars.gsfchi2 = eleRecoPtr->gsfTrack()->normalizedChi2();
313 
314  // Energy matching
315  allMVAVars.fbrem = eleRecoPtr->fbrem();
316 
317  allMVAVars.gsfhits = eleRecoPtr->gsfTrack()->hitPattern().trackerLayersWithMeasurement();
318  allMVAVars.expectedMissingInnerHits = eleRecoPtr->gsfTrack()
319  ->hitPattern().numberOfHits(reco::HitPattern::MISSING_INNER_HITS);
320 
322  conversions,
323  theBeamSpot->position());
324  double vertexFitProbability = -1.;
325  if(!conv_ref.isNull()) {
326  const reco::Vertex &vtx = conv_ref.get()->conversionVertex(); if (vtx.isValid()) {
327  vertexFitProbability = TMath::Prob( vtx.chi2(), vtx.ndof());
328  }
329  }
330  allMVAVars.convVtxFitProbability = vertexFitProbability;
331 
332  allMVAVars.EoP = eleRecoPtr->eSuperClusterOverP();
333  allMVAVars.eleEoPout = eleRecoPtr->eEleClusterOverPout();
334  float pAtVertex = eleRecoPtr->trackMomentumAtVtx().R();
335  allMVAVars.IoEmIoP = (1.0/eleRecoPtr->ecalEnergy()) - (1.0 / pAtVertex );
336 
337  // Geometrical matchings
338  allMVAVars.deta = eleRecoPtr->deltaEtaSuperClusterTrackAtVtx();
339  allMVAVars.dphi = eleRecoPtr->deltaPhiSuperClusterTrackAtVtx();
340  allMVAVars.detacalo = eleRecoPtr->deltaEtaSeedClusterTrackAtCalo();
341 
342  // Spectator variables
343  allMVAVars.pt = eleRecoPtr->pt();
344  float scEta = superCluster->eta();
345  constexpr float ebeeSplit = 1.479;
346  allMVAVars.isBarrel = ( std::abs(scEta) < ebeeSplit );
347  allMVAVars.isEndcap = ( std::abs(scEta) >= ebeeSplit );
348  allMVAVars.SCeta = scEta;
349  allMVAVars.pt = eleRecoPtr->pt();
350 
351  constrainMVAVariables(allMVAVars);
352 
353  std::vector<float> vars;
354 
355  if( isEndcapCategory( findCategory( eleRecoPtr ) ) ) {
356  vars = std::move( packMVAVariables(allMVAVars.see,
357  allMVAVars.spp,
358  allMVAVars.OneMinusE1x5E5x5,
359  allMVAVars.R9,
360  allMVAVars.etawidth,
361  allMVAVars.phiwidth,
362  allMVAVars.HoE,
363  //Pure tracking variables
364  allMVAVars.kfhits,
365  allMVAVars.kfchi2,
366  allMVAVars.gsfchi2,
367  // Energy matching
368  allMVAVars.fbrem,
369  allMVAVars.gsfhits,
370  allMVAVars.expectedMissingInnerHits,
371  allMVAVars.convVtxFitProbability,
372  allMVAVars.EoP,
373  allMVAVars.eleEoPout,
374  allMVAVars.IoEmIoP,
375  // Geometrical matchings
376  allMVAVars.deta,
377  allMVAVars.dphi,
378  allMVAVars.detacalo,
379 
380  allMVAVars.pt,
381  allMVAVars.SCeta,
382  // Endcap only variables
383  allMVAVars.PreShowerOverRaw)
384  );
385  } else {
386  vars = std::move( packMVAVariables(allMVAVars.see,
387  allMVAVars.spp,
388  allMVAVars.OneMinusE1x5E5x5,
389  allMVAVars.R9,
390  allMVAVars.etawidth,
391  allMVAVars.phiwidth,
392  allMVAVars.HoE,
393  //Pure tracking variables
394  allMVAVars.kfhits,
395  allMVAVars.kfchi2,
396  allMVAVars.gsfchi2,
397  // Energy matching
398  allMVAVars.fbrem,
399  allMVAVars.gsfhits,
400  allMVAVars.expectedMissingInnerHits,
401  allMVAVars.convVtxFitProbability,
402  allMVAVars.EoP,
403  allMVAVars.eleEoPout,
404  allMVAVars.IoEmIoP,
405  // Geometrical matchings
406  allMVAVars.deta,
407  allMVAVars.dphi,
408  allMVAVars.detacalo,
409  allMVAVars.pt,
410  allMVAVars.SCeta)
411  );
412  }
413  return vars;
414 }
bool isAvailable() const
Definition: Ref.h:576
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:252
bool isValid() const
Tells whether the vertex is valid.
Definition: Vertex.h:68
#define NULL
Definition: scimark2.h:8
#define constexpr
std::vector< float > packMVAVariables(const Args...args) const
reco::TrackRef closestCtfTrackRef() const
override the reco::GsfElectron::closestCtfTrackRef method, to access the internal storage of the trac...
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:244
int findCategory(const edm::Ptr< reco::Candidate > &particle) const override
bool isNull() const
Checks for null.
Definition: Ref.h:249
double ndof() const
Definition: Vertex.h:105
Analysis-level electron class.
Definition: Electron.h:52
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)
def move(src, dest)
Definition: eostools.py:510
int ElectronMVAEstimatorRun2Spring16GeneralPurpose::findCategory ( const edm::Ptr< reco::Candidate > &  particle) const
overridevirtual

Implements AnyMVAEstimatorRun2Base.

Definition at line 130 of file ElectronMVAEstimatorRun2Spring16GeneralPurpose.cc.

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

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

130  {
131 
132  // Try to cast the particle into a reco particle.
133  // This should work for both reco and pat.
134  const edm::Ptr<reco::GsfElectron> eleRecoPtr = ( edm::Ptr<reco::GsfElectron> )particle;
135  if( eleRecoPtr.get() == NULL )
136  throw cms::Exception("MVA failure: ")
137  << " given particle is expected to be reco::GsfElectron or pat::Electron," << std::endl
138  << " but appears to be neither" << std::endl;
139  return findCategory(eleRecoPtr.get());
140 }
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:160
#define NULL
Definition: scimark2.h:8
int findCategory(const edm::Ptr< reco::Candidate > &particle) const override
int ElectronMVAEstimatorRun2Spring16GeneralPurpose::findCategory ( const reco::GsfElectron particle) const

Definition at line 142 of file ElectronMVAEstimatorRun2Spring16GeneralPurpose.cc.

References funct::abs(), CAT_EB1_PT10plus, CAT_EB2_PT10plus, CAT_EE_PT10plus, PVValHelper::eta, isEndcapCategory(), reco::GsfElectron::superCluster(), and UNDEFINED.

142  {
143  float eta = eleRecoPtr->superCluster()->eta();
144 
145  //
146  // Determine the category
147  //
148  int iCategory = UNDEFINED;
149  const float ebSplit = 0.800;// barrel is split into two regions
150  const float ebeeSplit = 1.479; // division between barrel and endcap
151 
152 
153  if (std::abs(eta) < ebSplit)
154  iCategory = CAT_EB1_PT10plus;
155 
156  if (std::abs(eta) >= ebSplit && std::abs(eta) < ebeeSplit)
157  iCategory = CAT_EB2_PT10plus;
158 
159  if (std::abs(eta) >= ebeeSplit)
160  iCategory = CAT_EE_PT10plus;
161 
162  return iCategory;
163 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
virtual const std::string& ElectronMVAEstimatorRun2Spring16GeneralPurpose::getName ( void  ) const
inlinefinaloverridevirtual
virtual int ElectronMVAEstimatorRun2Spring16GeneralPurpose::getNCategories ( ) const
inlineoverridevirtual
virtual const std::string& ElectronMVAEstimatorRun2Spring16GeneralPurpose::getTag ( void  ) const
inlinefinaloverridevirtual
void ElectronMVAEstimatorRun2Spring16GeneralPurpose::init ( const std::vector< std::string >  weightFileNames)

Definition at line 26 of file ElectronMVAEstimatorRun2Spring16GeneralPurpose.cc.

References createSingleReader(), Exception, gbrForest_s, mps_fire::i, nCategories, and candidateChargeBTagComputer_cfi::weightFile.

Referenced by ElectronMVAEstimatorRun2Spring16GeneralPurpose().

26  {
27  if( (int)(weightFileNames.size()) != nCategories )
28  throw cms::Exception("MVA config failure: ")
29  << "wrong number of weightfiles" << std::endl;
30 
31  gbrForest_s.clear();
32  // Create a TMVA reader object for each category
33  for(int i=0; i<nCategories; i++){
34 
35  // Use unique_ptr so that all readers are properly cleaned up
36  // when the vector clear() is called in the destructor
37 
40 
41  }
42 
43 }
std::unique_ptr< const GBRForest > createSingleReader(const int iCategory, const edm::FileInPath &weightFile)
bool ElectronMVAEstimatorRun2Spring16GeneralPurpose::isEndcapCategory ( int  category) const
float ElectronMVAEstimatorRun2Spring16GeneralPurpose::mvaValue ( const edm::Ptr< reco::Candidate > &  particle,
const edm::Event iEvent 
) const
overridevirtual

Implements AnyMVAEstimatorRun2Base.

Definition at line 79 of file ElectronMVAEstimatorRun2Spring16GeneralPurpose.cc.

References fillMVAVariables(), findCategory(), and eostools::move().

Referenced by mvaValue(), and setConsumes().

79  {
80 
81  const int iCategory = findCategory( particle );
82  const std::vector<float> vars = std::move( fillMVAVariables( particle, iEvent ) );
83  return mvaValue(iCategory, vars);
84 }
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
def move(src, dest)
Definition: eostools.py:510
float ElectronMVAEstimatorRun2Spring16GeneralPurpose::mvaValue ( const reco::GsfElectron particle,
const edm::EventBase iEvent 
) const

Definition at line 87 of file ElectronMVAEstimatorRun2Spring16GeneralPurpose.cc.

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

87  {
90  iEvent.getByLabel(conversionsLabelAOD_, conversions);
91  iEvent.getByLabel(beamSpotLabel_, beamSpot);
92  const int iCategory = findCategory( particle );
93  const std::vector<float> vars = std::move( fillMVAVariables( particle, conversions, beamSpot.product() ) );
94  return mvaValue(iCategory, vars);
95 }
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
T const * product() const
Definition: Handle.h:81
bool getByLabel(InputTag const &, Handle< T > &) const
Definition: EventBase.h:94
def move(src, dest)
Definition: eostools.py:510
float ElectronMVAEstimatorRun2Spring16GeneralPurpose::mvaValue ( const int  iCategory,
const std::vector< float > &  vars 
) const

Definition at line 98 of file ElectronMVAEstimatorRun2Spring16GeneralPurpose.cc.

References gather_cfg::cout, debug, gbrForest_s, MethodName_, and mps_fire::result.

98  {
99  const float result = gbrForest_s.at(iCategory)->GetClassifier(vars.data());
100 
101  const bool debug = false;
102  if(debug) {
103  std::cout << " *** Inside the class MethodName_ " << MethodName_ << std::endl;
104  std::cout << " bin " << iCategory
105  << " fbrem " << vars[11]
106  << " kfchi2 " << vars[9]
107  << " mykfhits " << vars[8]
108  << " gsfchi2 " << vars[10]
109  << " deta " << vars[18]
110  << " dphi " << vars[19]
111  << " detacalo " << vars[20]
112  << " see " << vars[0]
113  << " spp " << vars[1]
114  << " etawidth " << vars[4]
115  << " phiwidth " << vars[5]
116  << " OneMinusE1x5E5x5 " << vars[2]
117  << " R9 " << vars[3]
118  << " HoE " << vars[6]
119  << " EoP " << vars[15]
120  << " IoEmIoP " << vars[17]
121  << " eleEoPout " << vars[16]
122  << " eta " << vars[24]
123  << " pt " << vars[21] << std::endl;
124  std::cout << " ### MVA " << result << std::endl;
125  }
126 
127  return result;
128 }
#define debug
Definition: HDRShower.cc:19
void ElectronMVAEstimatorRun2Spring16GeneralPurpose::setConsumes ( edm::ConsumesCollector &&  cc) const
finaloverridevirtual

Reimplemented from AnyMVAEstimatorRun2Base.

Definition at line 64 of file ElectronMVAEstimatorRun2Spring16GeneralPurpose.cc.

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

Referenced by getTag().

64  {
65 
66  // All tokens for event content needed by this MVA
67 
68  // Beam spot (same for AOD and miniAOD)
70 
71  // Conversions collection (different names in AOD and miniAOD)
74 
75 
76 }
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

AllVariables ElectronMVAEstimatorRun2Spring16GeneralPurpose::allMVAVars_
private
const edm::InputTag ElectronMVAEstimatorRun2Spring16GeneralPurpose::beamSpotLabel_
private
const edm::InputTag ElectronMVAEstimatorRun2Spring16GeneralPurpose::conversionsLabelAOD_
private
const edm::InputTag ElectronMVAEstimatorRun2Spring16GeneralPurpose::conversionsLabelMiniAOD_
private
std::vector< std::unique_ptr<const GBRForest> > ElectronMVAEstimatorRun2Spring16GeneralPurpose::gbrForest_s
private

Definition at line 136 of file ElectronMVAEstimatorRun2Spring16GeneralPurpose.h.

Referenced by init(), and mvaValue().

const std::string ElectronMVAEstimatorRun2Spring16GeneralPurpose::MethodName_
private
const std::string ElectronMVAEstimatorRun2Spring16GeneralPurpose::name_ = "ElectronMVAEstimatorRun2Spring16GeneralPurpose"
private

Definition at line 129 of file ElectronMVAEstimatorRun2Spring16GeneralPurpose.h.

Referenced by getName().

const int ElectronMVAEstimatorRun2Spring16GeneralPurpose::nCategories = 3

Definition at line 28 of file ElectronMVAEstimatorRun2Spring16GeneralPurpose.h.

Referenced by getNCategories(), and init().

const std::string ElectronMVAEstimatorRun2Spring16GeneralPurpose::tag_
private

Definition at line 133 of file ElectronMVAEstimatorRun2Spring16GeneralPurpose.h.

Referenced by getTag().