CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Types | Public Member Functions | Public Attributes | Private Attributes
ElectronMVAEstimatorRun2Spring15NonTrig Class Reference

#include <ElectronMVAEstimatorRun2Spring15NonTrig.h>

Inheritance diagram for ElectronMVAEstimatorRun2Spring15NonTrig:
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)
 
 ElectronMVAEstimatorRun2Spring15NonTrig (const edm::ParameterSet &conf)
 
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
 
virtual const std::string & getName () const overridefinal
 
virtual int getNCategories () const override
 
virtual const std::string & getTag () const overridefinal
 
bool isEndcapCategory (int category) const
 
float mvaValue (const edm::Ptr< reco::Candidate > &particle, const edm::Event &) const override
 
void setConsumes (edm::ConsumesCollector &&) const overridefinal
 
 ~ElectronMVAEstimatorRun2Spring15NonTrig ()
 
- 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 > > 
_gbrForests
 
const std::string _MethodName
 
const std::string _name = "ElectronMVAEstimatorRun2Spring15NonTrig"
 
const std::string _tag
 

Detailed Description

Definition at line 23 of file ElectronMVAEstimatorRun2Spring15NonTrig.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

ElectronMVAEstimatorRun2Spring15NonTrig::ElectronMVAEstimatorRun2Spring15NonTrig ( const edm::ParameterSet conf)

Definition at line 13 of file ElectronMVAEstimatorRun2Spring15NonTrig.cc.

References _gbrForests, createSingleReader(), Exception, edm::ParameterSet::getParameter(), i, and nCategories.

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 
24  if( (int)(weightFileNames.size()) != nCategories )
25  throw cms::Exception("MVA config failure: ")
26  << "wrong number of weightfiles" << std::endl;
27 
28  _gbrForests.clear();
29  // Create a TMVA reader object for each category
30  for(int i=0; i<nCategories; i++){
31 
32  // Use unique_ptr so that all readers are properly cleaned up
33  // when the vector clear() is called in the destructor
34 
35  edm::FileInPath weightFile( weightFileNames[i] );
36  _gbrForests.push_back( createSingleReader(i, weightFile ) );
37 
38  }
39 
40 }
T getParameter(std::string const &) const
std::vector< std::unique_ptr< const GBRForest > > _gbrForests
int i
Definition: DBlmapReader.cc:9
AnyMVAEstimatorRun2Base(const edm::ParameterSet &conf)
std::unique_ptr< const GBRForest > createSingleReader(const int iCategory, const edm::FileInPath &weightFile)
ElectronMVAEstimatorRun2Spring15NonTrig::~ElectronMVAEstimatorRun2Spring15NonTrig ( )

Definition at line 43 of file ElectronMVAEstimatorRun2Spring15NonTrig.cc.

43  {
44 }

Member Function Documentation

void ElectronMVAEstimatorRun2Spring15NonTrig::constrainMVAVariables ( AllVariables allMVAVars) const

Definition at line 418 of file ElectronMVAEstimatorRun2Spring15NonTrig.cc.

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

Referenced by fillMVAVariables().

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

Definition at line 151 of file ElectronMVAEstimatorRun2Spring15NonTrig.cc.

References _allMVAVars, _MethodName, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::convVtxFitProbability, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::deta, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::detacalo, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::dphi, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::eClass, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::eleEoPout, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::EoP, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::etawidth, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::expectedInnerHits, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::expectedMissingInnerHits, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::fbrem, edm::FileInPath::fullPath(), ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::gsfchi2, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::gsfhits, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::HoE, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::IoEmIoP, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::isBarrel, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::isEndcap, isEndcapCategory(), ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::kfchi2, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::kfhits, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::mcCBmatchingCategory, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::mcEventWeight, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::OneMinusE1x5E5x5, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::pfRelIso, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::phiwidth, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::PreShowerOverRaw, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::pt, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::R9, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::SCeta, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::see, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::spp, groupFilesInBlocks::temp, and ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::vtxconv.

Referenced by ElectronMVAEstimatorRun2Spring15NonTrig().

151  {
152 
153  //
154  // Create the reader
155  //
156  TMVA::Reader tmpTMVAReader( "!Color:Silent:!Error" );
157 
158  //
159  // Configure all variables and spectators. Note: the order and names
160  // must match what is found in the xml weights file!
161  //
162  // Pure ECAL -> shower shapes
163  tmpTMVAReader.AddVariable("ele_oldsigmaietaieta", &_allMVAVars.see);
164  tmpTMVAReader.AddVariable("ele_oldsigmaiphiiphi", &_allMVAVars.spp);
165  tmpTMVAReader.AddVariable("ele_oldcircularity", &_allMVAVars.OneMinusE1x5E5x5);
166  tmpTMVAReader.AddVariable("ele_oldr9", &_allMVAVars.R9);
167  tmpTMVAReader.AddVariable("ele_scletawidth", &_allMVAVars.etawidth);
168  tmpTMVAReader.AddVariable("ele_sclphiwidth", &_allMVAVars.phiwidth);
169  tmpTMVAReader.AddVariable("ele_he", &_allMVAVars.HoE);
170  // Endcap only variables
171  if( isEndcapCategory(iCategory) )
172  tmpTMVAReader.AddVariable("ele_psEoverEraw", &_allMVAVars.PreShowerOverRaw);
173 
174  //Pure tracking variables
175  tmpTMVAReader.AddVariable("ele_kfhits", &_allMVAVars.kfhits);
176  tmpTMVAReader.AddVariable("ele_kfchi2", &_allMVAVars.kfchi2);
177  tmpTMVAReader.AddVariable("ele_gsfchi2", &_allMVAVars.gsfchi2);
178 
179  // Energy matching
180  tmpTMVAReader.AddVariable("ele_fbrem", &_allMVAVars.fbrem);
181 
182  tmpTMVAReader.AddVariable("ele_gsfhits", &_allMVAVars.gsfhits);
183  tmpTMVAReader.AddVariable("ele_expected_inner_hits", &_allMVAVars.expectedMissingInnerHits);
184  tmpTMVAReader.AddVariable("ele_conversionVertexFitProbability", &_allMVAVars.convVtxFitProbability);
185 
186  tmpTMVAReader.AddVariable("ele_ep", &_allMVAVars.EoP);
187  tmpTMVAReader.AddVariable("ele_eelepout", &_allMVAVars.eleEoPout);
188  tmpTMVAReader.AddVariable("ele_IoEmIop", &_allMVAVars.IoEmIoP);
189 
190  // Geometrical matchings
191  tmpTMVAReader.AddVariable("ele_deltaetain", &_allMVAVars.deta);
192  tmpTMVAReader.AddVariable("ele_deltaphiin", &_allMVAVars.dphi);
193  tmpTMVAReader.AddVariable("ele_deltaetaseed", &_allMVAVars.detacalo);
194 
195  // Spectator variables
196  tmpTMVAReader.AddSpectator("ele_pT", &_allMVAVars.pt);
197  tmpTMVAReader.AddSpectator("ele_isbarrel", &_allMVAVars.isBarrel);
198  tmpTMVAReader.AddSpectator("ele_isendcap", &_allMVAVars.isEndcap);
199  tmpTMVAReader.AddSpectator("scl_eta", &_allMVAVars.SCeta);
200 
201  tmpTMVAReader.AddSpectator("ele_eClass", &_allMVAVars.eClass);
202  tmpTMVAReader.AddSpectator("ele_pfRelIso", &_allMVAVars.pfRelIso);
203  tmpTMVAReader.AddSpectator("ele_expected_inner_hits", &_allMVAVars.expectedInnerHits);
204  tmpTMVAReader.AddSpectator("ele_vtxconv", &_allMVAVars.vtxconv);
205  tmpTMVAReader.AddSpectator("mc_event_weight", &_allMVAVars.mcEventWeight);
206  tmpTMVAReader.AddSpectator("mc_ele_CBmatching_category", &_allMVAVars.mcCBmatchingCategory);
207 
208  //
209  // Book the method and set up the weights file
210  //
211  std::unique_ptr<TMVA::IMethod> temp( tmpTMVAReader.BookMVA(_MethodName , weightFile.fullPath() ) );
212 
213  return std::unique_ptr<const GBRForest> ( new GBRForest( dynamic_cast<TMVA::MethodBDT*>( tmpTMVAReader.FindMVA(_MethodName) ) ) );
214 }
std::string fullPath() const
Definition: FileInPath.cc:184
std::vector< float > ElectronMVAEstimatorRun2Spring15NonTrig::fillMVAVariables ( const edm::Ptr< reco::Candidate > &  particle,
const edm::Event iEvent 
) const
overridevirtual

Implements AnyMVAEstimatorRun2Base.

Definition at line 218 of file ElectronMVAEstimatorRun2Spring15NonTrig.cc.

References _beamSpotLabel, _conversionsLabelAOD, _conversionsLabelMiniAOD, funct::abs(), reco::Vertex::chi2(), constexpr, constrainMVAVariables(), conversions_cfi::conversions, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::convVtxFitProbability, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::deta, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::detacalo, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::dphi, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::eClass, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::eleEoPout, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::EoP, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::etawidth, Exception, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::expectedInnerHits, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::expectedMissingInnerHits, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::fbrem, findCategory(), edm::Ptr< T >::get(), edm::Ref< C, T, F >::get(), edm::Event::getByLabel(), ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::gsfchi2, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::gsfhits, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::HoE, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::IoEmIoP, edm::Ref< C, T, F >::isAvailable(), ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::isBarrel, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::isEndcap, isEndcapCategory(), edm::Ref< C, T, F >::isNonnull(), edm::Ref< C, T, F >::isNull(), reco::Vertex::isValid(), edm::HandleBase::isValid(), ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::kfchi2, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::kfhits, ConversionTools::matchedConversion(), ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::mcCBmatchingCategory, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::mcEventWeight, reco::HitPattern::MISSING_INNER_HITS, eostools::move(), reco::Vertex::ndof(), NULL, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::OneMinusE1x5E5x5, AnyMVAEstimatorRun2Base::packMVAVariables(), ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::pfRelIso, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::phiwidth, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::PreShowerOverRaw, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::pt, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::R9, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::SCeta, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::see, ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::spp, and ElectronMVAEstimatorRun2Spring15NonTrig::AllVariables::vtxconv.

Referenced by mvaValue().

219  {
220 
221  //
222  // Declare all value maps corresponding to the products we defined earlier
223  //
224  edm::Handle<reco::BeamSpot> theBeamSpot;
226 
227  // Get data needed for conversion rejection
228  iEvent.getByLabel(_beamSpotLabel, theBeamSpot);
229 
230  // Conversions in miniAOD and AOD have different names,
231  // but the same type, so we use the same handle with different tokens.
232  iEvent.getByLabel(_conversionsLabelAOD, conversions);
233  if( !conversions.isValid() )
234  iEvent.getByLabel(_conversionsLabelMiniAOD, conversions);
235 
236  // Make sure everything is retrieved successfully
237  if(! (theBeamSpot.isValid()
238  && conversions.isValid() )
239  )
240  throw cms::Exception("MVA failure: ")
241  << "Failed to retrieve event content needed for this MVA"
242  << std::endl
243  << "Check python MVA configuration file."
244  << std::endl;
245 
246  // Try to cast the particle into a reco particle.
247  // This should work for both reco and pat.
248  const edm::Ptr<reco::GsfElectron> eleRecoPtr = ( edm::Ptr<reco::GsfElectron> )particle;
249  if( eleRecoPtr.get() == NULL )
250  throw cms::Exception("MVA failure: ")
251  << " given particle is expected to be reco::GsfElectron or pat::Electron," << std::endl
252  << " but appears to be neither" << std::endl;
253 
254  // Both pat and reco particles have exactly the same accessors, so we use a reco ptr
255  // throughout the code, with a single exception as of this writing, handled separately below.
256  auto superCluster = eleRecoPtr->superCluster();
257 
258  AllVariables allMVAVars;
259 
260  // Pure ECAL -> shower shapes
261  allMVAVars.see = eleRecoPtr->full5x5_sigmaIetaIeta();
262  allMVAVars.spp = eleRecoPtr->full5x5_sigmaIphiIphi();
263  allMVAVars.OneMinusE1x5E5x5 = 1. - eleRecoPtr->full5x5_e1x5() / eleRecoPtr->full5x5_e5x5();
264  allMVAVars.R9 = eleRecoPtr->full5x5_r9();
265  allMVAVars.etawidth = superCluster->etaWidth();
266  allMVAVars.phiwidth = superCluster->phiWidth();
267  allMVAVars.HoE = eleRecoPtr->hadronicOverEm();
268  // Endcap only variables
269  allMVAVars.PreShowerOverRaw = superCluster->preshowerEnergy() / superCluster->rawEnergy();
270 
271  // To get to CTF track information in pat::Electron, we have to have the pointer
272  // to pat::Electron, it is not accessible from the pointer to reco::GsfElectron.
273  // This behavior is reported and is expected to change in the future (post-7.4.5 some time).
274  bool validKF= false;
275  reco::TrackRef myTrackRef = eleRecoPtr->closestCtfTrackRef();
276  const edm::Ptr<pat::Electron> elePatPtr(eleRecoPtr);
277  // Check if this is really a pat::Electron, and if yes, get the track ref from this new
278  // pointer instead
279  if( elePatPtr.get() != NULL )
280  myTrackRef = elePatPtr->closestCtfTrackRef();
281  validKF = (myTrackRef.isAvailable() && (myTrackRef.isNonnull()) );
282 
283  //Pure tracking variables
284  allMVAVars.kfhits = (validKF) ? myTrackRef->hitPattern().trackerLayersWithMeasurement() : -1. ;
285  allMVAVars.kfchi2 = (validKF) ? myTrackRef->normalizedChi2() : 0;
286  allMVAVars.gsfchi2 = eleRecoPtr->gsfTrack()->normalizedChi2();
287 
288  // Energy matching
289  allMVAVars.fbrem = eleRecoPtr->fbrem();
290 
291  allMVAVars.gsfhits = eleRecoPtr->gsfTrack()->hitPattern().trackerLayersWithMeasurement();
292  allMVAVars.expectedMissingInnerHits = eleRecoPtr->gsfTrack()
293  ->hitPattern().numberOfHits(reco::HitPattern::MISSING_INNER_HITS);
294 
296  conversions,
297  theBeamSpot->position());
298  double vertexFitProbability = -1.;
299  if(!conv_ref.isNull()) {
300  const reco::Vertex &vtx = conv_ref.get()->conversionVertex(); if (vtx.isValid()) {
301  vertexFitProbability = TMath::Prob( vtx.chi2(), vtx.ndof());
302  }
303  }
304  allMVAVars.convVtxFitProbability = vertexFitProbability;
305 
306  allMVAVars.EoP = eleRecoPtr->eSuperClusterOverP();
307  allMVAVars.eleEoPout = eleRecoPtr->eEleClusterOverPout();
308  float pAtVertex = eleRecoPtr->trackMomentumAtVtx().R();
309  allMVAVars.IoEmIoP = (1.0/eleRecoPtr->ecalEnergy()) - (1.0 / pAtVertex );
310 
311  // Geometrical matchings
312  allMVAVars.deta = eleRecoPtr->deltaEtaSuperClusterTrackAtVtx();
313  allMVAVars.dphi = eleRecoPtr->deltaPhiSuperClusterTrackAtVtx();
314  allMVAVars.detacalo = eleRecoPtr->deltaEtaSeedClusterTrackAtCalo();
315 
316  // Spectator variables
317  allMVAVars.pt = eleRecoPtr->pt();
318  float scEta = superCluster->eta();
319  constexpr float ebeeSplit = 1.479;
320  allMVAVars.isBarrel = ( std::abs(scEta) < ebeeSplit );
321  allMVAVars.isEndcap = ( std::abs(scEta) >= ebeeSplit );
322  allMVAVars.SCeta = scEta;
323  // The spectator variables below were examined for training, but
324  // are not necessary for evaluating the discriminator, so they are
325  // given dummy values (the specator variables above are also unimportant).
326  // They are introduced only to match the definition of the discriminator
327  // in the weights file.
328  constexpr unsigned nines = 999;
329  allMVAVars.eClass = nines;
330  allMVAVars.pfRelIso = nines;
331  allMVAVars.expectedInnerHits = nines;
332  allMVAVars.vtxconv = nines;
333  allMVAVars.mcEventWeight = nines;
334  allMVAVars.mcCBmatchingCategory = nines;
335 
336  constrainMVAVariables(allMVAVars);
337 
338  std::vector<float> vars;
339 
340  if( isEndcapCategory( findCategory( particle ) ) ) {
341  vars = std::move( packMVAVariables(allMVAVars.see,
342  allMVAVars.spp,
343  allMVAVars.OneMinusE1x5E5x5,
344  allMVAVars.R9,
345  allMVAVars.etawidth,
346  allMVAVars.phiwidth,
347  allMVAVars.HoE,
348  // Endcap only variables
349  allMVAVars.PreShowerOverRaw,
350  //Pure tracking variables
351  allMVAVars.kfhits,
352  allMVAVars.kfchi2,
353  allMVAVars.gsfchi2,
354  // Energy matching
355  allMVAVars.fbrem,
356  allMVAVars.gsfhits,
357  allMVAVars.expectedMissingInnerHits,
358  allMVAVars.convVtxFitProbability,
359  allMVAVars.EoP,
360  allMVAVars.eleEoPout,
361  allMVAVars.IoEmIoP,
362  // Geometrical matchings
363  allMVAVars.deta,
364  allMVAVars.dphi,
365  allMVAVars.detacalo,
366  // Spectator variables
367  allMVAVars.pt,
368  allMVAVars.isBarrel,
369  allMVAVars.isEndcap,
370  allMVAVars.SCeta,
371  allMVAVars.eClass,
372  allMVAVars.pfRelIso,
373  allMVAVars.expectedInnerHits,
374  allMVAVars.vtxconv,
375  allMVAVars.mcEventWeight,
376  allMVAVars.mcCBmatchingCategory)
377  );
378  } else {
379  vars = std::move( packMVAVariables(allMVAVars.see,
380  allMVAVars.spp,
381  allMVAVars.OneMinusE1x5E5x5,
382  allMVAVars.R9,
383  allMVAVars.etawidth,
384  allMVAVars.phiwidth,
385  allMVAVars.HoE,
386  //Pure tracking variables
387  allMVAVars.kfhits,
388  allMVAVars.kfchi2,
389  allMVAVars.gsfchi2,
390  // Energy matching
391  allMVAVars.fbrem,
392  allMVAVars.gsfhits,
393  allMVAVars.expectedMissingInnerHits,
394  allMVAVars.convVtxFitProbability,
395  allMVAVars.EoP,
396  allMVAVars.eleEoPout,
397  allMVAVars.IoEmIoP,
398  // Geometrical matchings
399  allMVAVars.deta,
400  allMVAVars.dphi,
401  allMVAVars.detacalo,
402  // Spectator variables
403  allMVAVars.pt,
404  allMVAVars.isBarrel,
405  allMVAVars.isEndcap,
406  allMVAVars.SCeta,
407  allMVAVars.eClass,
408  allMVAVars.pfRelIso,
409  allMVAVars.expectedInnerHits,
410  allMVAVars.vtxconv,
411  allMVAVars.mcEventWeight,
412  allMVAVars.mcCBmatchingCategory)
413  );
414  }
415  return vars;
416 }
bool isAvailable() const
Definition: Ref.h:576
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:252
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:160
bool isValid() const
Tells whether the vertex is valid.
Definition: Vertex.h:60
int findCategory(const edm::Ptr< reco::Candidate > &particle) const override
#define NULL
Definition: scimark2.h:8
#define constexpr
std::vector< float > packMVAVariables(const Args...args) const
def move
Definition: eostools.py:510
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double chi2() const
chi-squares
Definition: Vertex.h:88
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:244
bool isValid() const
Definition: HandleBase.h:75
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:418
bool isNull() const
Checks for null.
Definition: Ref.h:249
double ndof() const
Definition: Vertex.h:95
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 ElectronMVAEstimatorRun2Spring15NonTrig::findCategory ( const edm::Ptr< reco::Candidate > &  particle) const
overridevirtual

Implements AnyMVAEstimatorRun2Base.

Definition at line 97 of file ElectronMVAEstimatorRun2Spring15NonTrig.cc.

References funct::abs(), CAT_EB1_PT10plus, CAT_EB1_PT5to10, CAT_EB2_PT10plus, CAT_EB2_PT5to10, CAT_EE_PT10plus, CAT_EE_PT5to10, eta, edm::Ptr< T >::get(), NULL, EnergyCorrector::pt, and UNDEFINED.

Referenced by fillMVAVariables(), and mvaValue().

97  {
98 
99  // Try to cast the particle into a reco particle.
100  // This should work for both reco and pat.
101  const edm::Ptr<reco::GsfElectron> eleRecoPtr = ( edm::Ptr<reco::GsfElectron> )particle;
102  if( eleRecoPtr.get() == NULL )
103  throw cms::Exception("MVA failure: ")
104  << " given particle is expected to be reco::GsfElectron or pat::Electron," << std::endl
105  << " but appears to be neither" << std::endl;
106 
107  float pt = eleRecoPtr->pt();
108  float eta = eleRecoPtr->superCluster()->eta();
109 
110  //
111  // Determine the category
112  //
113  int iCategory = UNDEFINED;
114  const float ptSplit = 10; // we have above and below 10 GeV categories
115  const float ebSplit = 0.800;// barrel is split into two regions
116  const float ebeeSplit = 1.479; // division between barrel and endcap
117 
118  if (pt < ptSplit && std::abs(eta) < ebSplit)
119  iCategory = CAT_EB1_PT5to10;
120 
121  if (pt < ptSplit && std::abs(eta) >= ebSplit && std::abs(eta) < ebeeSplit)
122  iCategory = CAT_EB2_PT5to10;
123 
124  if (pt < ptSplit && std::abs(eta) >= ebeeSplit)
125  iCategory = CAT_EE_PT5to10;
126 
127  if (pt >= ptSplit && std::abs(eta) < ebSplit)
128  iCategory = CAT_EB1_PT10plus;
129 
130  if (pt >= ptSplit && std::abs(eta) >= ebSplit && std::abs(eta) < ebeeSplit)
131  iCategory = CAT_EB2_PT10plus;
132 
133  if (pt >= ptSplit && std::abs(eta) >= ebeeSplit)
134  iCategory = CAT_EE_PT10plus;
135 
136  return iCategory;
137 }
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:160
#define NULL
Definition: scimark2.h:8
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
virtual const std::string& ElectronMVAEstimatorRun2Spring15NonTrig::getName ( void  ) const
inlinefinaloverridevirtual

Implements AnyMVAEstimatorRun2Base.

Definition at line 100 of file ElectronMVAEstimatorRun2Spring15NonTrig.h.

References _name.

Referenced by plotting.Plot::draw().

virtual int ElectronMVAEstimatorRun2Spring15NonTrig::getNCategories ( ) const
inlineoverridevirtual
virtual const std::string& ElectronMVAEstimatorRun2Spring15NonTrig::getTag ( void  ) const
inlinefinaloverridevirtual

Implements AnyMVAEstimatorRun2Base.

Definition at line 101 of file ElectronMVAEstimatorRun2Spring15NonTrig.h.

References _tag.

bool ElectronMVAEstimatorRun2Spring15NonTrig::isEndcapCategory ( int  category) const
float ElectronMVAEstimatorRun2Spring15NonTrig::mvaValue ( const edm::Ptr< reco::Candidate > &  particle,
const edm::Event iEvent 
) const
overridevirtual

Implements AnyMVAEstimatorRun2Base.

Definition at line 62 of file ElectronMVAEstimatorRun2Spring15NonTrig.cc.

References _gbrForests, _MethodName, gather_cfg::cout, debug, fillMVAVariables(), findCategory(), eostools::move(), and mps_fire::result.

62  {
63 
64  const int iCategory = findCategory( particle );
65  const std::vector<float> vars = std::move( fillMVAVariables( particle, iEvent ) );
66  const float result = _gbrForests.at(iCategory)->GetClassifier(vars.data());
67 
68  const bool debug = false;
69  if(debug) {
70  std::cout << " *** Inside the class _MethodName " << _MethodName << std::endl;
71  std::cout << " bin " << iCategory
72  << " fbrem " << vars[11]
73  << " kfchi2 " << vars[9]
74  << " mykfhits " << vars[8]
75  << " gsfchi2 " << vars[10]
76  << " deta " << vars[18]
77  << " dphi " << vars[19]
78  << " detacalo " << vars[20]
79  << " see " << vars[0]
80  << " spp " << vars[1]
81  << " etawidth " << vars[4]
82  << " phiwidth " << vars[5]
83  << " OneMinusE1x5E5x5 " << vars[2]
84  << " R9 " << vars[3]
85  << " HoE " << vars[6]
86  << " EoP " << vars[15]
87  << " IoEmIoP " << vars[17]
88  << " eleEoPout " << vars[16]
89  << " eta " << vars[24]
90  << " pt " << vars[21] << std::endl;
91  std::cout << " ### MVA " << result << std::endl;
92  }
93 
94  return result;
95 }
std::vector< std::unique_ptr< const GBRForest > > _gbrForests
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
tuple result
Definition: mps_fire.py:95
def move
Definition: eostools.py:510
#define debug
Definition: HDRShower.cc:19
tuple cout
Definition: gather_cfg.py:145
void ElectronMVAEstimatorRun2Spring15NonTrig::setConsumes ( edm::ConsumesCollector &&  cc) const
finaloverridevirtual

Reimplemented from AnyMVAEstimatorRun2Base.

Definition at line 47 of file ElectronMVAEstimatorRun2Spring15NonTrig.cc.

References _beamSpotLabel, _conversionsLabelAOD, and _conversionsLabelMiniAOD.

47  {
48 
49  // All tokens for event content needed by this MVA
50 
51  // Beam spot (same for AOD and miniAOD)
53 
54  // Conversions collection (different names in AOD and miniAOD)
57 
58 
59 }
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 ElectronMVAEstimatorRun2Spring15NonTrig::_allMVAVars
private

Definition at line 133 of file ElectronMVAEstimatorRun2Spring15NonTrig.h.

Referenced by createSingleReader().

const edm::InputTag ElectronMVAEstimatorRun2Spring15NonTrig::_beamSpotLabel
private

Definition at line 139 of file ElectronMVAEstimatorRun2Spring15NonTrig.h.

Referenced by fillMVAVariables(), and setConsumes().

const edm::InputTag ElectronMVAEstimatorRun2Spring15NonTrig::_conversionsLabelAOD
private

Definition at line 141 of file ElectronMVAEstimatorRun2Spring15NonTrig.h.

Referenced by fillMVAVariables(), and setConsumes().

const edm::InputTag ElectronMVAEstimatorRun2Spring15NonTrig::_conversionsLabelMiniAOD
private

Definition at line 142 of file ElectronMVAEstimatorRun2Spring15NonTrig.h.

Referenced by fillMVAVariables(), and setConsumes().

std::vector< std::unique_ptr<const GBRForest> > ElectronMVAEstimatorRun2Spring15NonTrig::_gbrForests
private
const std::string ElectronMVAEstimatorRun2Spring15NonTrig::_MethodName
private

Definition at line 132 of file ElectronMVAEstimatorRun2Spring15NonTrig.h.

Referenced by createSingleReader(), and mvaValue().

const std::string ElectronMVAEstimatorRun2Spring15NonTrig::_name = "ElectronMVAEstimatorRun2Spring15NonTrig"
private
const std::string ElectronMVAEstimatorRun2Spring15NonTrig::_tag
private

Definition at line 126 of file ElectronMVAEstimatorRun2Spring15NonTrig.h.

Referenced by getTag().

const int ElectronMVAEstimatorRun2Spring15NonTrig::nCategories = 6