CMS 3D CMS Logo

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

#include <SoftElectronMVAEstimator.h>

Classes

struct  Configuration
 

Public Member Functions

UInt_t GetMVABin (int pu, double eta, double pt) const
 
double mva (const reco::GsfElectron &myElectron, const edm::Event &evt)
 
 SoftElectronMVAEstimator (const Configuration &)
 
 ~SoftElectronMVAEstimator ()
 

Private Member Functions

void bindVariables ()
 
void init ()
 

Private Attributes

const Configuration cfg_
 
Float_t DeltaEtaTrackEcalSeed
 
Float_t deta
 
Float_t detacalo
 
Float_t dphi
 
Float_t EBremOverDeltaP
 
Float_t eleEoPout
 
Float_t EoP
 
Float_t eta
 
Float_t etawidth
 
Float_t EtotOvePin
 
Float_t fbrem
 
std::vector< TMVA::Reader * > fmvaReader
 
Float_t gsfchi2
 
Float_t HoE
 
Float_t IoEmIoP
 
Float_t kfchi2
 
Float_t kfhits
 
Float_t logSigmaEtaEta
 
std::vector< std::string > mvaWeightFiles_
 
Float_t nPV
 
Float_t OneMinusE1x5E5x5
 
Float_t phiwidth
 
Float_t PreShowerOverRaw
 
Float_t pt
 
Float_t R9
 
Float_t see
 
Float_t SigmaPtOverPt
 
Float_t spp
 
TMVA::Reader * tmvaReader_
 

Detailed Description

Definition at line 12 of file SoftElectronMVAEstimator.h.

Constructor & Destructor Documentation

SoftElectronMVAEstimator::SoftElectronMVAEstimator ( const Configuration cfg)

Definition at line 8 of file SoftElectronMVAEstimator.cc.

References cfg_, gather_cfg::cout, DeltaEtaTrackEcalSeed, deta, detacalo, dphi, EBremOverDeltaP, eleEoPout, eta, etawidth, EtotOvePin, fbrem, fmvaReader, gsfchi2, HoE, i, compare_using_db::ifile, IoEmIoP, kfchi2, kfhits, logSigmaEtaEta, nPV, OneMinusE1x5E5x5, phiwidth, PreShowerOverRaw, pt, R9, see, SigmaPtOverPt, spp, AlCaHLTBitMon_QueryRunRegistry::string, tmvaReader_, and SoftElectronMVAEstimator::Configuration::vweightsfiles.

8  :cfg_(cfg){
9  std::vector<std::string> weightsfiles;
10  std::string path_mvaWeightFileEleID;
11  for(unsigned ifile=0 ; ifile < cfg_.vweightsfiles.size() ; ++ifile) {
12  path_mvaWeightFileEleID = edm::FileInPath ( cfg_.vweightsfiles[ifile].c_str() ).fullPath();
13  weightsfiles.push_back(path_mvaWeightFileEleID);
14  }
15 
16  for (unsigned int i=0;i<fmvaReader.size(); ++i) {
17  if (fmvaReader[i]) delete fmvaReader[i];
18  }
19  fmvaReader.clear();
20 
21  //initialize
22  //Define expected number of bins
23  UInt_t ExpectedNBins = 1;
24 
25  //Check number of weight files given
26  if (ExpectedNBins != cfg_.vweightsfiles.size() ) {
27  std::cout << "Error: Expected Number of bins = " << ExpectedNBins << " does not equal to weightsfiles.size() = "
28  << cfg_.vweightsfiles.size() << std::endl;
29 
30  assert(ExpectedNBins == cfg_.vweightsfiles.size());
31  }
32 
33 
34  for (unsigned int i=0;i<ExpectedNBins; ++i) {
35  tmvaReader_ = new TMVA::Reader("!Color:Silent");
36  tmvaReader_->AddVariable("fbrem", &fbrem);
37  tmvaReader_->AddVariable("EtotOvePin", &EtotOvePin);
38  tmvaReader_->AddVariable("EClusOverPout", &eleEoPout);
39  tmvaReader_->AddVariable("EBremOverDeltaP", &EBremOverDeltaP);
40  tmvaReader_->AddVariable("logSigmaEtaEta", &logSigmaEtaEta);
41  tmvaReader_->AddVariable("DeltaEtaTrackEcalSeed", &DeltaEtaTrackEcalSeed);
42  tmvaReader_->AddVariable("HoE", &HoE);
43  tmvaReader_->AddVariable("gsfchi2", &gsfchi2);
44  tmvaReader_->AddVariable("kfchi2", &kfchi2);
45  tmvaReader_->AddVariable("kfhits", &kfhits);
46  tmvaReader_->AddVariable("SigmaPtOverPt", &SigmaPtOverPt);
47  tmvaReader_->AddVariable("deta", &deta);
48  tmvaReader_->AddVariable("dphi", &dphi);
49  tmvaReader_->AddVariable("detacalo", &detacalo);
50  tmvaReader_->AddVariable("see", &see);
51  tmvaReader_->AddVariable("spp", &spp);
52  tmvaReader_->AddVariable("R9", &R9);
53  tmvaReader_->AddVariable("etawidth", &etawidth);
54  tmvaReader_->AddVariable("phiwidth", &phiwidth);
55  tmvaReader_->AddVariable("e1x5e5x5", &OneMinusE1x5E5x5);
56  tmvaReader_->AddVariable("IoEmIoP", &IoEmIoP);
57  tmvaReader_->AddVariable("PreShowerOverRaw", &PreShowerOverRaw);
58  tmvaReader_->AddVariable("nPV", &nPV);
59 
60  tmvaReader_->AddVariable( "pt", &pt);
61  tmvaReader_->AddVariable( "eta", &eta);
62 
63  tmvaReader_->AddSpectator( "pt", &pt);
64  tmvaReader_->AddSpectator( "eta", &eta);
65 
66 // tmvaReader_->AddSpectator( "nPV", &nPV);
67 
68  // Taken from Daniele (his mail from the 30/11)
69  // tmvaReader_->BookMVA("BDTSimpleCat","../Training/weights_Root527b_3Depth_DanVarConvRej_2PtBins_10Pt_800TPrune5_Min100Events_NoBjets_half/TMVA_BDTSimpleCat.weights.xm");
70  // training of the 7/12 with Nvtx added
71  tmvaReader_->BookMVA("BDT",weightsfiles[i]);
72  fmvaReader.push_back(tmvaReader_);
73 // delete tmvaReader_;
74  }
75 
76 }
int i
Definition: DBlmapReader.cc:9
std::vector< TMVA::Reader * > fmvaReader
tuple cout
Definition: gather_cfg.py:121
SoftElectronMVAEstimator::~SoftElectronMVAEstimator ( )

Definition at line 79 of file SoftElectronMVAEstimator.cc.

References fmvaReader, and i.

80 {
81  for (unsigned int i=0;i<fmvaReader.size(); ++i) {
82  if (fmvaReader[i]) delete fmvaReader[i];
83  }
84 }
int i
Definition: DBlmapReader.cc:9
std::vector< TMVA::Reader * > fmvaReader

Member Function Documentation

void SoftElectronMVAEstimator::bindVariables ( )
private

Definition at line 157 of file SoftElectronMVAEstimator.cc.

References deta, detacalo, dphi, eleEoPout, EoP, fbrem, gsfchi2, kfchi2, and OneMinusE1x5E5x5.

Referenced by mva().

157  {
158  if(fbrem < -1.)
159  fbrem = -1.;
160 
161  deta = fabs(deta);
162  if(deta > 0.06)
163  deta = 0.06;
164 
165 
166  dphi = fabs(dphi);
167  if(dphi > 0.6)
168  dphi = 0.6;
169 
170 
171  if(EoP > 20.)
172  EoP = 20.;
173 
174  if(eleEoPout > 20.)
175  eleEoPout = 20.;
176 
177 
178  detacalo = fabs(detacalo);
179  if(detacalo > 0.2)
180  detacalo = 0.2;
181 
182  if(OneMinusE1x5E5x5 < -1.)
183  OneMinusE1x5E5x5 = -1;
184 
185  if(OneMinusE1x5E5x5 > 2.)
186  OneMinusE1x5E5x5 = 2.;
187 
188 
189 
190  if(gsfchi2 > 200.)
191  gsfchi2 = 200;
192 
193 
194  if(kfchi2 > 10.)
195  kfchi2 = 10.;
196 
197 }
UInt_t SoftElectronMVAEstimator::GetMVABin ( int  pu,
double  eta,
double  pt 
) const

Definition at line 87 of file SoftElectronMVAEstimator.cc.

References newFWLiteAna::bin, getHLTprescales::index, and nPV.

87  {
88 
89  //Default is to return the first bin
90  unsigned int bin = 0;
91 
92  bool ptrange[3],etarange[3],purange[2];
93  ptrange[0]=pt > 2 && pt < 5;
94  ptrange[1]=pt > 5 && pt < 10;
95  ptrange[2]=pt > 10;
96  etarange[0]=fabs(eta) < 0.8;
97  etarange[1]=fabs(eta) > 0.8 && fabs(eta) <1.4;
98  etarange[2]=fabs(eta) > 1.4;
99  purange[0]=nPV<=20;
100  purange[1]=nPV>20;
101 
102  int index=0;
103  for(int kPU=0;kPU<2;kPU++)
104  for(int kETA=0;kETA<3;kETA++)
105  for(int kPT=0;kPT<3;kPT++){
106  if (purange[kPU] && ptrange[kPT] && etarange[kETA]) bin=index;
107  index++;
108  }
109  return bin;
110 }
void SoftElectronMVAEstimator::init ( )
private
double SoftElectronMVAEstimator::mva ( const reco::GsfElectron myElectron,
const edm::Event evt 
)

Definition at line 114 of file SoftElectronMVAEstimator.cc.

References bindVariables(), reco::GsfElectron::closestCtfTrackRef(), reco::GsfElectron::deltaEtaEleClusterTrackAtCalo(), reco::GsfElectron::deltaEtaSeedClusterTrackAtCalo(), reco::GsfElectron::deltaEtaSuperClusterTrackAtVtx(), DeltaEtaTrackEcalSeed, reco::GsfElectron::deltaPhiSuperClusterTrackAtVtx(), deta, detacalo, dphi, reco::GsfElectron::e1x5(), reco::GsfElectron::e5x5(), EBremOverDeltaP, reco::GsfElectron::eEleClusterOverPout(), eleEoPout, reco::GsfElectron::eSuperClusterOverP(), eta, reco::LeafCandidate::eta(), etawidth, EtotOvePin, fbrem, reco::GsfElectron::fbrem(), fmvaReader, edm::Ref< C, T, F >::get(), edm::Event::getByLabel(), gsfchi2, reco::GsfElectron::gsfTrack(), reco::GsfElectron::hadronicOverEm(), HoE, edm::Ref< C, T, F >::isAvailable(), edm::Ref< C, T, F >::isNonnull(), kfchi2, kfhits, create_public_lumi_plots::log, logSigmaEtaEta, nPV, OneMinusE1x5E5x5, phiwidth, edm::Handle< T >::product(), pt, reco::LeafCandidate::pt(), query::result, see, reco::GsfElectron::sigmaEtaEta(), reco::GsfElectron::sigmaIetaIeta(), SigmaPtOverPt, reco::GsfElectron::superCluster(), reco::GsfElectron::trackMomentumAtEleClus(), and reco::GsfElectron::trackMomentumAtVtx().

Referenced by GsfElectronAlgo::isPreselected(), and GsfElectronAlgo::setMVAOutputs().

114  {
115 
116  edm::Handle<reco::VertexCollection> FullprimaryVertexCollection;
117  evt.getByLabel("offlinePrimaryVertices", FullprimaryVertexCollection);
118  const reco::VertexCollection pvc = *(FullprimaryVertexCollection.product());
119 
120  fbrem =myElectron.fbrem();
121  EtotOvePin =myElectron.eSuperClusterOverP();
122  eleEoPout =myElectron.eEleClusterOverPout();
123  float etot =myElectron.eSuperClusterOverP()*myElectron.trackMomentumAtVtx().R();
124  float eEcal =myElectron.eEleClusterOverPout()*myElectron.trackMomentumAtEleClus().R();
125  float dP =myElectron.trackMomentumAtVtx().R()-myElectron.trackMomentumAtEleClus().R();
126  EBremOverDeltaP =(etot-eEcal)/dP;
127  logSigmaEtaEta =log(myElectron.sigmaEtaEta());
129  HoE =myElectron.hadronicOverEm();
130 
131  bool validKF= false;
132  reco::TrackRef myTrackRef = myElectron.closestCtfTrackRef();
133  validKF = (myTrackRef.isAvailable() && myTrackRef.isNonnull());
134  kfchi2 =(validKF) ? myTrackRef->normalizedChi2() : 0 ;
135  kfhits =(validKF) ? myTrackRef->hitPattern().trackerLayersWithMeasurement() : -1. ;
136  gsfchi2 =myElectron.gsfTrack()->normalizedChi2();
137  SigmaPtOverPt =myElectron.gsfTrack().get()->ptModeError()/myElectron.gsfTrack().get()->ptMode() ;
138  deta =myElectron.deltaEtaSuperClusterTrackAtVtx();
139  dphi =myElectron.deltaPhiSuperClusterTrackAtVtx();
141  see =myElectron.sigmaIetaIeta();
142  etawidth =myElectron.superCluster()->etaWidth();
143  phiwidth =myElectron.superCluster()->phiWidth();
144  OneMinusE1x5E5x5 =(myElectron.e5x5()) !=0. ? 1.-(myElectron.e1x5()/myElectron.e5x5()) : -1. ;
145  pt =myElectron.pt();
146  eta =myElectron.eta();
147  nPV=pvc.size();
148 
149  bindVariables();
150 // double result= fmvaReader[GetMVABin(nPV,eta,pt)]->EvaluateMVA("BDT");
151  double result= fmvaReader[0]->EvaluateMVA("BDT");
152 // double result = tmvaReader_->EvaluateMVA("BDT");
153  return result;
154 }
float eSuperClusterOverP() const
Definition: GsfElectron.h:230
math::XYZVectorF trackMomentumAtVtx() const
Definition: GsfElectron.h:273
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
float fbrem() const
Definition: GsfElectron.h:653
bool isAvailable() const
Definition: Ref.h:276
TrackRef closestCtfTrackRef() const
Definition: GsfElectron.h:186
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
float deltaEtaSuperClusterTrackAtVtx() const
Definition: GsfElectron.h:234
float sigmaIetaIeta() const
Definition: GsfElectron.h:386
float hadronicOverEm() const
Definition: GsfElectron.h:410
virtual SuperClusterRef superCluster() const
reference to a SuperCluster
Definition: GsfElectron.h:169
float deltaPhiSuperClusterTrackAtVtx() const
Definition: GsfElectron.h:237
tuple result
Definition: query.py:137
float eEleClusterOverPout() const
Definition: GsfElectron.h:233
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
std::vector< TMVA::Reader * > fmvaReader
virtual float eta() const GCC11_FINAL
momentum pseudorapidity
float deltaEtaEleClusterTrackAtCalo() const
Definition: GsfElectron.h:236
float e1x5() const
Definition: GsfElectron.h:388
T const * product() const
Definition: Handle.h:81
math::XYZVectorF trackMomentumAtEleClus() const
Definition: GsfElectron.h:276
float e5x5() const
Definition: GsfElectron.h:390
float deltaEtaSeedClusterTrackAtCalo() const
Definition: GsfElectron.h:235
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:242
virtual float pt() const GCC11_FINAL
transverse momentum
float sigmaEtaEta() const
Definition: GsfElectron.h:385
virtual GsfTrackRef gsfTrack() const
reference to a GsfTrack
Definition: GsfElectron.h:170

Member Data Documentation

const Configuration SoftElectronMVAEstimator::cfg_
private

Definition at line 26 of file SoftElectronMVAEstimator.h.

Referenced by SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::DeltaEtaTrackEcalSeed
private

Definition at line 35 of file SoftElectronMVAEstimator.h.

Referenced by mva(), and SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::deta
private

Definition at line 42 of file SoftElectronMVAEstimator.h.

Referenced by bindVariables(), mva(), and SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::detacalo
private

Definition at line 44 of file SoftElectronMVAEstimator.h.

Referenced by bindVariables(), mva(), and SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::dphi
private

Definition at line 43 of file SoftElectronMVAEstimator.h.

Referenced by bindVariables(), mva(), and SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::EBremOverDeltaP
private

Definition at line 33 of file SoftElectronMVAEstimator.h.

Referenced by mva(), and SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::eleEoPout
private

Definition at line 53 of file SoftElectronMVAEstimator.h.

Referenced by bindVariables(), mva(), and SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::EoP
private

Definition at line 52 of file SoftElectronMVAEstimator.h.

Referenced by bindVariables().

Float_t SoftElectronMVAEstimator::eta
private

Definition at line 61 of file SoftElectronMVAEstimator.h.

Referenced by mva(), and SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::etawidth
private

Definition at line 47 of file SoftElectronMVAEstimator.h.

Referenced by mva(), and SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::EtotOvePin
private

Definition at line 32 of file SoftElectronMVAEstimator.h.

Referenced by mva(), and SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::fbrem
private

Definition at line 31 of file SoftElectronMVAEstimator.h.

Referenced by bindVariables(), mva(), and SoftElectronMVAEstimator().

std::vector<TMVA::Reader*> SoftElectronMVAEstimator::fmvaReader
private
Float_t SoftElectronMVAEstimator::gsfchi2
private

Definition at line 38 of file SoftElectronMVAEstimator.h.

Referenced by bindVariables(), mva(), and SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::HoE
private

Definition at line 51 of file SoftElectronMVAEstimator.h.

Referenced by mva(), and SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::IoEmIoP
private

Definition at line 57 of file SoftElectronMVAEstimator.h.

Referenced by SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::kfchi2
private

Definition at line 36 of file SoftElectronMVAEstimator.h.

Referenced by bindVariables(), mva(), and SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::kfhits
private

Definition at line 37 of file SoftElectronMVAEstimator.h.

Referenced by mva(), and SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::logSigmaEtaEta
private

Definition at line 34 of file SoftElectronMVAEstimator.h.

Referenced by mva(), and SoftElectronMVAEstimator().

std::vector<std::string> SoftElectronMVAEstimator::mvaWeightFiles_
private

Definition at line 27 of file SoftElectronMVAEstimator.h.

Float_t SoftElectronMVAEstimator::nPV
private

Definition at line 64 of file SoftElectronMVAEstimator.h.

Referenced by GetMVABin(), mva(), and SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::OneMinusE1x5E5x5
private

Definition at line 49 of file SoftElectronMVAEstimator.h.

Referenced by bindVariables(), mva(), and SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::phiwidth
private

Definition at line 48 of file SoftElectronMVAEstimator.h.

Referenced by mva(), and SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::PreShowerOverRaw
private

Definition at line 58 of file SoftElectronMVAEstimator.h.

Referenced by SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::pt
private

Definition at line 62 of file SoftElectronMVAEstimator.h.

Referenced by mva(), and SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::R9
private

Definition at line 56 of file SoftElectronMVAEstimator.h.

Referenced by SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::see
private

Definition at line 46 of file SoftElectronMVAEstimator.h.

Referenced by mva(), and SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::SigmaPtOverPt
private

Definition at line 39 of file SoftElectronMVAEstimator.h.

Referenced by mva(), and SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::spp
private

Definition at line 55 of file SoftElectronMVAEstimator.h.

Referenced by SoftElectronMVAEstimator().

TMVA::Reader* SoftElectronMVAEstimator::tmvaReader_
private

Definition at line 29 of file SoftElectronMVAEstimator.h.

Referenced by SoftElectronMVAEstimator().