CMS 3D CMS Logo

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

#include <ElectronMVAEstimatorRun2Spring16HZZ.h>

Inheritance diagram for ElectronMVAEstimatorRun2Spring16HZZ:
AnyMVAEstimatorRun2Base

Classes

struct  AllVariables
 

Public Types

enum  mvaCategories {
  UNDEFINED = -1, CAT_EB1_PT5to10 = 0, CAT_EB2_PT5to10 = 1, CAT_EE_PT5to10 = 2,
  CAT_EB1_PT10plus = 3, CAT_EB2_PT10plus = 4, CAT_EE_PT10plus = 5
}
 

Public Member Functions

void constrainMVAVariables (AllVariables &) const
 
std::unique_ptr< const GBRForestcreateSingleReader (const int iCategory, const edm::FileInPath &weightFile)
 
 ElectronMVAEstimatorRun2Spring16HZZ (const edm::ParameterSet &conf)
 
 ElectronMVAEstimatorRun2Spring16HZZ ()
 
 ElectronMVAEstimatorRun2Spring16HZZ (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
 
 ~ElectronMVAEstimatorRun2Spring16HZZ ()
 
- 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 = 6
 
- 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_ = "ElectronMVAEstimatorRun2Spring16HZZ"
 
const std::string tag_
 

Detailed Description

Definition at line 22 of file ElectronMVAEstimatorRun2Spring16HZZ.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

ElectronMVAEstimatorRun2Spring16HZZ::ElectronMVAEstimatorRun2Spring16HZZ ( const edm::ParameterSet conf)

Definition at line 13 of file ElectronMVAEstimatorRun2Spring16HZZ.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
AnyMVAEstimatorRun2Base(const edm::ParameterSet &conf)
void init(const std::vector< std::string > weightFileNames)
ElectronMVAEstimatorRun2Spring16HZZ::ElectronMVAEstimatorRun2Spring16HZZ ( )

Definition at line 45 of file ElectronMVAEstimatorRun2Spring16HZZ.cc.

45  :
AnyMVAEstimatorRun2Base(const edm::ParameterSet &conf)
ElectronMVAEstimatorRun2Spring16HZZ::ElectronMVAEstimatorRun2Spring16HZZ ( const std::string &  mvaTag,
const std::string &  conversionsTag = "reducedEgamma:reducedConversions",
const std::string &  beamspotTag = "offlineBeamSpot" 
)
ElectronMVAEstimatorRun2Spring16HZZ::~ElectronMVAEstimatorRun2Spring16HZZ ( )

Definition at line 60 of file ElectronMVAEstimatorRun2Spring16HZZ.cc.

Referenced by ElectronMVAEstimatorRun2Spring16HZZ().

60  {
61 }

Member Function Documentation

void ElectronMVAEstimatorRun2Spring16HZZ::constrainMVAVariables ( AllVariables allMVAVars) const

Definition at line 468 of file ElectronMVAEstimatorRun2Spring16HZZ.cc.

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

Referenced by fillMVAVariables(), and getTag().

468  {
469 
470  // Check that variables do not have crazy values
471 
472  if(allMVAVars.fbrem < -1.)
473  allMVAVars.fbrem = -1.;
474 
475  allMVAVars.deta = fabs(allMVAVars.deta);
476  if(allMVAVars.deta > 0.06)
477  allMVAVars.deta = 0.06;
478 
479 
480  allMVAVars.dphi = fabs(allMVAVars.dphi);
481  if(allMVAVars.dphi > 0.6)
482  allMVAVars.dphi = 0.6;
483 
484 
485  if(allMVAVars.EoP > 20.)
486  allMVAVars.EoP = 20.;
487 
488  if(allMVAVars.eleEoPout > 20.)
489  allMVAVars.eleEoPout = 20.;
490 
491 
492  allMVAVars.detacalo = fabs(allMVAVars.detacalo);
493  if(allMVAVars.detacalo > 0.2)
494  allMVAVars.detacalo = 0.2;
495 
496  if(allMVAVars.OneMinusE1x5E5x5 < -1.)
497  allMVAVars.OneMinusE1x5E5x5 = -1;
498 
499  if(allMVAVars.OneMinusE1x5E5x5 > 2.)
500  allMVAVars.OneMinusE1x5E5x5 = 2.;
501 
502 
503 
504  if(allMVAVars.R9 > 5)
505  allMVAVars.R9 = 5;
506 
507  if(allMVAVars.gsfchi2 > 200.)
508  allMVAVars.gsfchi2 = 200;
509 
510 
511  if(allMVAVars.kfchi2 > 10.)
512  allMVAVars.kfchi2 = 10.;
513 
514 
515 }
std::unique_ptr< const GBRForest > ElectronMVAEstimatorRun2Spring16HZZ::createSingleReader ( const int  iCategory,
const edm::FileInPath weightFile 
)

Definition at line 187 of file ElectronMVAEstimatorRun2Spring16HZZ.cc.

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

Referenced by init(), and isEndcapCategory().

187  {
188 
189  //
190  // Create the reader
191  //
192  TMVA::Reader tmpTMVAReader( "!Color:Silent:!Error" );
193 
194  //
195  // Configure all variables and spectators. Note: the order and names
196  // must match what is found in the xml weights file!
197  //
198 
199 
200  // Pure ECAL -> shower shapes
201  tmpTMVAReader.AddVariable("ele_oldsigmaietaieta", &allMVAVars_.see);
202  tmpTMVAReader.AddVariable("ele_oldsigmaiphiiphi", &allMVAVars_.spp);
203  tmpTMVAReader.AddVariable("ele_oldcircularity", &allMVAVars_.OneMinusE1x5E5x5);
204  tmpTMVAReader.AddVariable("ele_oldr9", &allMVAVars_.R9);
205  tmpTMVAReader.AddVariable("ele_scletawidth", &allMVAVars_.etawidth);
206  tmpTMVAReader.AddVariable("ele_sclphiwidth", &allMVAVars_.phiwidth);
207  tmpTMVAReader.AddVariable("ele_oldhe", &allMVAVars_.HoE);
208 
209  //Pure tracking variables
210  tmpTMVAReader.AddVariable("ele_kfhits", &allMVAVars_.kfhits);
211  tmpTMVAReader.AddVariable("ele_kfchi2", &allMVAVars_.kfchi2);
212  tmpTMVAReader.AddVariable("ele_gsfchi2", &allMVAVars_.gsfchi2);
213 
214  // Energy matching
215  tmpTMVAReader.AddVariable("ele_fbrem", &allMVAVars_.fbrem);
216 
217  tmpTMVAReader.AddVariable("ele_gsfhits", &allMVAVars_.gsfhits);
218  tmpTMVAReader.AddVariable("ele_expected_inner_hits", &allMVAVars_.expectedMissingInnerHits);
219  tmpTMVAReader.AddVariable("ele_conversionVertexFitProbability", &allMVAVars_.convVtxFitProbability);
220 
221  tmpTMVAReader.AddVariable("ele_ep", &allMVAVars_.EoP);
222  tmpTMVAReader.AddVariable("ele_eelepout", &allMVAVars_.eleEoPout);
223  tmpTMVAReader.AddVariable("ele_IoEmIop", &allMVAVars_.IoEmIoP);
224 
225  // Geometrical matchings
226  tmpTMVAReader.AddVariable("ele_deltaetain", &allMVAVars_.deta);
227  tmpTMVAReader.AddVariable("ele_deltaphiin", &allMVAVars_.dphi);
228  tmpTMVAReader.AddVariable("ele_deltaetaseed", &allMVAVars_.detacalo);
229 
230  // Endcap only variables
231  if( isEndcapCategory(iCategory) )
232  tmpTMVAReader.AddVariable("ele_psEoverEraw", &allMVAVars_.PreShowerOverRaw);
233 
234 
235  // Spectator variables
236  tmpTMVAReader.AddSpectator("ele_pt", &allMVAVars_.pt);
237  tmpTMVAReader.AddSpectator("ele_isEE", &allMVAVars_.isBarrel);
238  tmpTMVAReader.AddSpectator("ele_isEB", &allMVAVars_.isEndcap);
239  tmpTMVAReader.AddSpectator("ele_isEBEtaGap", &allMVAVars_.isEndcap);
240  tmpTMVAReader.AddSpectator("ele_isEBPhiGap", &allMVAVars_.isEndcap);
241  tmpTMVAReader.AddSpectator("ele_isEBEEGap", &allMVAVars_.isEndcap);
242  tmpTMVAReader.AddSpectator("ele_isEERingGap", &allMVAVars_.isEndcap);
243  tmpTMVAReader.AddSpectator("ele_isEEDeeGap", &allMVAVars_.isEndcap);
244  tmpTMVAReader.AddSpectator("ele_isEE", &allMVAVars_.SCeta);
245  tmpTMVAReader.AddSpectator("scl_eta", &allMVAVars_.SCeta);
246  tmpTMVAReader.AddSpectator("ele_eClass", &allMVAVars_.eClass);
247  tmpTMVAReader.AddSpectator("mc_ele_matchedFromCB", &allMVAVars_.mcCBmatchingCategory);
248 
249  //
250  // Book the method and set up the weights file
251  //
252  tmpTMVAReader.BookMVA(MethodName_ , weightFile.fullPath());
253 
254  return std::unique_ptr<const GBRForest> ( new GBRForest( dynamic_cast<TMVA::MethodBDT*>( tmpTMVAReader.FindMVA(MethodName_) ) ) );
255 }
std::string fullPath() const
Definition: FileInPath.cc:184
std::vector< float > ElectronMVAEstimatorRun2Spring16HZZ::fillMVAVariables ( const edm::Ptr< reco::Candidate > &  particle,
const edm::Event iEvent 
) const
overridevirtual

Implements AnyMVAEstimatorRun2Base.

Definition at line 259 of file ElectronMVAEstimatorRun2Spring16HZZ.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().

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

Definition at line 299 of file ElectronMVAEstimatorRun2Spring16HZZ.cc.

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

300  {
301 
302 
303  // Both pat and reco particles have exactly the same accessors, so we use a reco ptr
304  // throughout the code, with a single exception as of this writing, handled separately below.
305  auto superCluster = eleRecoPtr->superCluster();
306 
307  AllVariables allMVAVars;
308 
309  // Pure ECAL -> shower shapes
310  allMVAVars.see = eleRecoPtr->full5x5_sigmaIetaIeta();
311  allMVAVars.spp = eleRecoPtr->full5x5_sigmaIphiIphi();
312  allMVAVars.OneMinusE1x5E5x5 = 1. - eleRecoPtr->full5x5_e1x5() / eleRecoPtr->full5x5_e5x5();
313  allMVAVars.R9 = eleRecoPtr->full5x5_r9();
314  allMVAVars.etawidth = superCluster->etaWidth();
315  allMVAVars.phiwidth = superCluster->phiWidth();
316  allMVAVars.HoE = eleRecoPtr->full5x5_hcalOverEcal(); //hadronicOverEm();
317  // Endcap only variables
318  allMVAVars.PreShowerOverRaw = superCluster->preshowerEnergy() / superCluster->rawEnergy();
319 
320  // To get to CTF track information in pat::Electron, we have to have the pointer
321  // to pat::Electron, it is not accessible from the pointer to reco::GsfElectron.
322  // This behavior is reported and is expected to change in the future (post-7.4.5 some time).
323  bool validKF= false;
324  reco::TrackRef myTrackRef = eleRecoPtr->closestCtfTrackRef();
325  const pat::Electron * elePatPtr = dynamic_cast<const pat::Electron *>(eleRecoPtr);
326  // Check if this is really a pat::Electron, and if yes, get the track ref from this new
327  // pointer instead
328  if( elePatPtr != NULL )
329  myTrackRef = elePatPtr->closestCtfTrackRef();
330  validKF = (myTrackRef.isAvailable() && (myTrackRef.isNonnull()) );
331 
332  //Pure tracking variables
333  allMVAVars.kfhits = (validKF) ? myTrackRef->hitPattern().trackerLayersWithMeasurement() : -1. ;
334  allMVAVars.kfchi2 = (validKF) ? myTrackRef->normalizedChi2() : 0;
335  allMVAVars.gsfchi2 = eleRecoPtr->gsfTrack()->normalizedChi2();
336 
337  // Energy matching
338  allMVAVars.fbrem = eleRecoPtr->fbrem();
339 
340  allMVAVars.gsfhits = eleRecoPtr->gsfTrack()->hitPattern().trackerLayersWithMeasurement();
341  allMVAVars.expectedMissingInnerHits = eleRecoPtr->gsfTrack()
342  ->hitPattern().numberOfHits(reco::HitPattern::MISSING_INNER_HITS);
343 
345  conversions,
346  theBeamSpot->position());
347  double vertexFitProbability = -1.;
348  if(!conv_ref.isNull()) {
349  const reco::Vertex &vtx = conv_ref.get()->conversionVertex(); if (vtx.isValid()) {
350  vertexFitProbability = TMath::Prob( vtx.chi2(), vtx.ndof());
351  }
352  }
353  allMVAVars.convVtxFitProbability = vertexFitProbability;
354 
355  allMVAVars.EoP = eleRecoPtr->eSuperClusterOverP();
356  allMVAVars.eleEoPout = eleRecoPtr->eEleClusterOverPout();
357  float pAtVertex = eleRecoPtr->trackMomentumAtVtx().R();
358  allMVAVars.IoEmIoP = (1.0/eleRecoPtr->ecalEnergy()) - (1.0 / pAtVertex );
359 
360  // Geometrical matchings
361  allMVAVars.deta = eleRecoPtr->deltaEtaSuperClusterTrackAtVtx();
362  allMVAVars.dphi = eleRecoPtr->deltaPhiSuperClusterTrackAtVtx();
363  allMVAVars.detacalo = eleRecoPtr->deltaEtaSeedClusterTrackAtCalo();
364 
365  // Spectator variables
366  allMVAVars.pt = eleRecoPtr->pt();
367  float scEta = superCluster->eta();
368  constexpr float ebeeSplit = 1.479;
369  allMVAVars.isBarrel = ( std::abs(scEta) < ebeeSplit );
370  allMVAVars.isEndcap = ( std::abs(scEta) >= ebeeSplit );
371  allMVAVars.SCeta = scEta;
372  // The spectator variables below were examined for training, but
373  // are not necessary for evaluating the discriminator, so they are
374  // given dummy values (the specator variables above are also unimportant).
375  // They are introduced only to match the definition of the discriminator
376  // in the weights file.
377  constexpr unsigned nines = 999;
378  allMVAVars.eClass = nines;
379  allMVAVars.pfRelIso = nines;
380  allMVAVars.expectedInnerHits = nines;
381  allMVAVars.vtxconv = nines;
382  allMVAVars.mcEventWeight = nines;
383  allMVAVars.mcCBmatchingCategory = nines;
384 
385  constrainMVAVariables(allMVAVars);
386 
387  std::vector<float> vars;
388 
389  if( isEndcapCategory( findCategory( eleRecoPtr ) ) ) {
390  vars = std::move( packMVAVariables(allMVAVars.see,
391  allMVAVars.spp,
392  allMVAVars.OneMinusE1x5E5x5,
393  allMVAVars.R9,
394  allMVAVars.etawidth,
395  allMVAVars.phiwidth,
396  allMVAVars.HoE,
397  //Pure tracking variables
398  allMVAVars.kfhits,
399  allMVAVars.kfchi2,
400  allMVAVars.gsfchi2,
401  // Energy matching
402  allMVAVars.fbrem,
403  allMVAVars.gsfhits,
404  allMVAVars.expectedMissingInnerHits,
405  allMVAVars.convVtxFitProbability,
406  allMVAVars.EoP,
407  allMVAVars.eleEoPout,
408  allMVAVars.IoEmIoP,
409  // Geometrical matchings
410  allMVAVars.deta,
411  allMVAVars.dphi,
412  allMVAVars.detacalo,
413  // Endcap only variables
414  allMVAVars.PreShowerOverRaw,
415 
416  // Spectator variables
417  allMVAVars.pt,
418  allMVAVars.isBarrel,
419  allMVAVars.isEndcap,
420  allMVAVars.SCeta,
421  allMVAVars.eClass,
422  allMVAVars.pfRelIso,
423  allMVAVars.expectedInnerHits,
424  allMVAVars.vtxconv,
425  allMVAVars.mcEventWeight,
426  allMVAVars.mcCBmatchingCategory)
427  );
428  } else {
429  vars = std::move( packMVAVariables(allMVAVars.see,
430  allMVAVars.spp,
431  allMVAVars.OneMinusE1x5E5x5,
432  allMVAVars.R9,
433  allMVAVars.etawidth,
434  allMVAVars.phiwidth,
435  allMVAVars.HoE,
436  //Pure tracking variables
437  allMVAVars.kfhits,
438  allMVAVars.kfchi2,
439  allMVAVars.gsfchi2,
440  // Energy matching
441  allMVAVars.fbrem,
442  allMVAVars.gsfhits,
443  allMVAVars.expectedMissingInnerHits,
444  allMVAVars.convVtxFitProbability,
445  allMVAVars.EoP,
446  allMVAVars.eleEoPout,
447  allMVAVars.IoEmIoP,
448  // Geometrical matchings
449  allMVAVars.deta,
450  allMVAVars.dphi,
451  allMVAVars.detacalo,
452  // Spectator variables
453  allMVAVars.pt,
454  allMVAVars.isBarrel,
455  allMVAVars.isEndcap,
456  allMVAVars.SCeta,
457  allMVAVars.eClass,
458  allMVAVars.pfRelIso,
459  allMVAVars.expectedInnerHits,
460  allMVAVars.vtxconv,
461  allMVAVars.mcEventWeight,
462  allMVAVars.mcCBmatchingCategory)
463  );
464  }
465  return vars;
466 }
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
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
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)
def move(src, dest)
Definition: eostools.py:510
int ElectronMVAEstimatorRun2Spring16HZZ::findCategory ( const edm::Ptr< reco::Candidate > &  particle) const
overridevirtual

Implements AnyMVAEstimatorRun2Base.

Definition at line 130 of file ElectronMVAEstimatorRun2Spring16HZZ.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 ElectronMVAEstimatorRun2Spring16HZZ::findCategory ( const reco::GsfElectron particle) const

Definition at line 142 of file ElectronMVAEstimatorRun2Spring16HZZ.cc.

References funct::abs(), CAT_EB1_PT10plus, CAT_EB1_PT5to10, CAT_EB2_PT10plus, CAT_EB2_PT5to10, CAT_EE_PT10plus, CAT_EE_PT5to10, stringResolutionProvider_cfi::eta, isEndcapCategory(), EnergyCorrector::pt, reco::LeafCandidate::pt(), reco::GsfElectron::superCluster(), and UNDEFINED.

142  {
143  float pt = eleRecoPtr->pt();
144  float eta = eleRecoPtr->superCluster()->eta();
145 
146  //
147  // Determine the category
148  //
149  int iCategory = UNDEFINED;
150  const float ptSplit = 10; // we have above and below 10 GeV categories
151  const float ebSplit = 0.800;// barrel is split into two regions
152  const float ebeeSplit = 1.479; // division between barrel and endcap
153 
154  if (pt < ptSplit && std::abs(eta) < ebSplit)
155  iCategory = CAT_EB1_PT5to10;
156 
157  if (pt < ptSplit && std::abs(eta) >= ebSplit && std::abs(eta) < ebeeSplit)
158  iCategory = CAT_EB2_PT5to10;
159 
160  if (pt < ptSplit && std::abs(eta) >= ebeeSplit)
161  iCategory = CAT_EE_PT5to10;
162 
163  if (pt >= ptSplit && std::abs(eta) < ebSplit)
164  iCategory = CAT_EB1_PT10plus;
165 
166  if (pt >= ptSplit && std::abs(eta) >= ebSplit && std::abs(eta) < ebeeSplit)
167  iCategory = CAT_EB2_PT10plus;
168 
169  if (pt >= ptSplit && std::abs(eta) >= ebeeSplit)
170  iCategory = CAT_EE_PT10plus;
171 
172  return iCategory;
173 }
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
virtual const std::string& ElectronMVAEstimatorRun2Spring16HZZ::getName ( void  ) const
inlinefinaloverridevirtual

Implements AnyMVAEstimatorRun2Base.

Definition at line 108 of file ElectronMVAEstimatorRun2Spring16HZZ.h.

References name_.

Referenced by plotting.Plot::draw().

virtual int ElectronMVAEstimatorRun2Spring16HZZ::getNCategories ( ) const
inlineoverridevirtual
virtual const std::string& ElectronMVAEstimatorRun2Spring16HZZ::getTag ( void  ) const
inlinefinaloverridevirtual
void ElectronMVAEstimatorRun2Spring16HZZ::init ( const std::vector< std::string >  weightFileNames)

Definition at line 26 of file ElectronMVAEstimatorRun2Spring16HZZ.cc.

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

Referenced by ElectronMVAEstimatorRun2Spring16HZZ().

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::vector< std::unique_ptr< const GBRForest > > gbrForest_s
std::unique_ptr< const GBRForest > createSingleReader(const int iCategory, const edm::FileInPath &weightFile)
bool ElectronMVAEstimatorRun2Spring16HZZ::isEndcapCategory ( int  category) const
float ElectronMVAEstimatorRun2Spring16HZZ::mvaValue ( const edm::Ptr< reco::Candidate > &  particle,
const edm::Event iEvent 
) const
overridevirtual

Implements AnyMVAEstimatorRun2Base.

Definition at line 79 of file ElectronMVAEstimatorRun2Spring16HZZ.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 }
std::vector< float > fillMVAVariables(const edm::Ptr< reco::Candidate > &particle, const edm::Event &) const override
float mvaValue(const edm::Ptr< reco::Candidate > &particle, const edm::Event &) const override
int findCategory(const edm::Ptr< reco::Candidate > &particle) const override
def move(src, dest)
Definition: eostools.py:510
float ElectronMVAEstimatorRun2Spring16HZZ::mvaValue ( const reco::GsfElectron particle,
const edm::EventBase iEvent 
) const

Definition at line 87 of file ElectronMVAEstimatorRun2Spring16HZZ.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 }
std::vector< float > fillMVAVariables(const edm::Ptr< reco::Candidate > &particle, const edm::Event &) const override
float mvaValue(const edm::Ptr< reco::Candidate > &particle, const edm::Event &) const override
T const * product() const
Definition: Handle.h:81
bool getByLabel(InputTag const &, Handle< T > &) const
Definition: EventBase.h:89
int findCategory(const edm::Ptr< reco::Candidate > &particle) const override
def move(src, dest)
Definition: eostools.py:510
float ElectronMVAEstimatorRun2Spring16HZZ::mvaValue ( const int  iCategory,
const std::vector< float > &  vars 
) const

Definition at line 98 of file ElectronMVAEstimatorRun2Spring16HZZ.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 }
std::vector< std::unique_ptr< const GBRForest > > gbrForest_s
#define debug
Definition: HDRShower.cc:19
void ElectronMVAEstimatorRun2Spring16HZZ::setConsumes ( edm::ConsumesCollector &&  cc) const
finaloverridevirtual

Reimplemented from AnyMVAEstimatorRun2Base.

Definition at line 64 of file ElectronMVAEstimatorRun2Spring16HZZ.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 ElectronMVAEstimatorRun2Spring16HZZ::allMVAVars_
private

Definition at line 143 of file ElectronMVAEstimatorRun2Spring16HZZ.h.

Referenced by createSingleReader().

const edm::InputTag ElectronMVAEstimatorRun2Spring16HZZ::beamSpotLabel_
private

Definition at line 149 of file ElectronMVAEstimatorRun2Spring16HZZ.h.

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

const edm::InputTag ElectronMVAEstimatorRun2Spring16HZZ::conversionsLabelAOD_
private

Definition at line 151 of file ElectronMVAEstimatorRun2Spring16HZZ.h.

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

const edm::InputTag ElectronMVAEstimatorRun2Spring16HZZ::conversionsLabelMiniAOD_
private

Definition at line 152 of file ElectronMVAEstimatorRun2Spring16HZZ.h.

Referenced by fillMVAVariables(), and setConsumes().

std::vector< std::unique_ptr<const GBRForest> > ElectronMVAEstimatorRun2Spring16HZZ::gbrForest_s
private

Definition at line 139 of file ElectronMVAEstimatorRun2Spring16HZZ.h.

Referenced by init(), and mvaValue().

const std::string ElectronMVAEstimatorRun2Spring16HZZ::MethodName_
private

Definition at line 142 of file ElectronMVAEstimatorRun2Spring16HZZ.h.

Referenced by createSingleReader(), and mvaValue().

const std::string ElectronMVAEstimatorRun2Spring16HZZ::name_ = "ElectronMVAEstimatorRun2Spring16HZZ"
private

Definition at line 132 of file ElectronMVAEstimatorRun2Spring16HZZ.h.

Referenced by getName().

const int ElectronMVAEstimatorRun2Spring16HZZ::nCategories = 6

Definition at line 28 of file ElectronMVAEstimatorRun2Spring16HZZ.h.

Referenced by getNCategories(), and init().

const std::string ElectronMVAEstimatorRun2Spring16HZZ::tag_
private

Definition at line 136 of file ElectronMVAEstimatorRun2Spring16HZZ.h.

Referenced by getTag().