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 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 assert(), cfg_, gather_cfg::cout, DeltaEtaTrackEcalSeed, deta, detacalo, dphi, EBremOverDeltaP, eleEoPout, eta, etawidth, EtotOvePin, fbrem, fmvaReader, contentValuesFiles::fullPath, 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
tuple cfg
Definition: looper.py:259
assert(m_qm.get())
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 185 of file SoftElectronMVAEstimator.cc.

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

Referenced by mva().

185  {
186  if(fbrem < -1.)
187  fbrem = -1.;
188 
189  deta = fabs(deta);
190  if(deta > 0.06)
191  deta = 0.06;
192 
193 
194  dphi = fabs(dphi);
195  if(dphi > 0.6)
196  dphi = 0.6;
197 
198 
199  //if(EoP > 20.)
200  // EoP = 20.;
201 
202  if(eleEoPout > 20.)
203  eleEoPout = 20.;
204 
205 
206  detacalo = fabs(detacalo);
207  if(detacalo > 0.2)
208  detacalo = 0.2;
209 
210  if(OneMinusE1x5E5x5 < -1.)
211  OneMinusE1x5E5x5 = -1;
212 
213  if(OneMinusE1x5E5x5 > 2.)
214  OneMinusE1x5E5x5 = 2.;
215 
216 
217 
218  if(gsfchi2 > 200.)
219  gsfchi2 = 200;
220 
221 
222  if(kfchi2 > 10.)
223  kfchi2 = 10.;
224 
225 }
UInt_t SoftElectronMVAEstimator::GetMVABin ( int  pu,
double  eta,
double  pt 
) const

Definition at line 87 of file SoftElectronMVAEstimator.cc.

References newFWLiteAna::bin, cmsHarvester::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(), cfg_, 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::ecalEnergy(), 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::getByToken(), gsfchi2, reco::GsfElectron::gsfTrack(), reco::GsfElectron::hcalOverEcalBc(), HoE, IoEmIoP, edm::Ref< C, T, F >::isAvailable(), edm::Ref< C, T, F >::isNonnull(), kfchi2, kfhits, cmsBatch::log, logSigmaEtaEta, nPV, OneMinusE1x5E5x5, reco::LeafCandidate::p(), phiwidth, PreShowerOverRaw, edm::Handle< T >::product(), pt, reco::LeafCandidate::pt(), R9, reco::GsfElectron::r9(), query::result, see, reco::GsfElectron::sigmaEtaEta(), reco::GsfElectron::sigmaIetaIeta(), reco::GsfElectron::sigmaIphiIphi(), SigmaPtOverPt, spp, reco::GsfElectron::superCluster(), reco::GsfElectron::trackMomentumAtEleClus(), reco::GsfElectron::trackMomentumAtVtx(), and SoftElectronMVAEstimator::Configuration::vtxCollection.

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

114  {
115 
116  edm::Handle<reco::VertexCollection> FullprimaryVertexCollection;
117  evt.getByToken(cfg_.vtxCollection, 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.hcalOverEcalBc();
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  spp =myElectron.sigmaIphiIphi();
143  R9 =myElectron.r9();
144  IoEmIoP = (1.0/myElectron.ecalEnergy()) - (1.0 / myElectron.p());
145  etawidth =myElectron.superCluster()->etaWidth();
146  phiwidth =myElectron.superCluster()->phiWidth();
147  OneMinusE1x5E5x5 =(myElectron.e5x5()) !=0. ? 1.-(myElectron.e1x5()/myElectron.e5x5()) : -1. ;
148  pt =myElectron.pt();
149  eta =myElectron.eta();
150  nPV=pvc.size();
151  PreShowerOverRaw=myElectron.superCluster()->preshowerEnergy() / myElectron.superCluster()->rawEnergy();
152 
153 /*
154  std::cout<<"fbrem "<<fbrem<<std::endl;
155  std::cout<<"EtotOvePin "<<EtotOvePin<<std::endl;
156  std::cout<<"eleEoPout "<<eleEoPout<<std::endl;
157  std::cout<<"EBremOverDeltaP "<<EBremOverDeltaP<<std::endl;
158  std::cout<<"logSigmaEtaEta "<<logSigmaEtaEta<<std::endl;
159  std::cout<<"DeltaEtaTrackEcalSeed "<<DeltaEtaTrackEcalSeed<<std::endl;
160  std::cout<<"HoE "<<HoE<<std::endl;
161  std::cout<<"kfchi2 "<<kfchi2<<std::endl;
162  std::cout<<"kfhits "<<kfhits<<std::endl;
163  std::cout<<"gsfchi2 "<<gsfchi2<<std::endl;
164  std::cout<<"SigmaPtOverPt "<<SigmaPtOverPt<<std::endl;
165  std::cout<<"deta "<<deta<<std::endl;
166  std::cout<<"dphi "<<dphi<<std::endl;
167  std::cout<<"detacalo "<<detacalo<<std::endl;
168  std::cout<<"see "<<see<<std::endl;
169  std::cout<< "spp " << spp<< std::endl;
170  std::cout<< "R9 " << R9<< std::endl;
171  std::cout<< "IoEmIoP " << IoEmIoP<< std::endl;
172  std::cout<<"etawidth "<<etawidth<<std::endl;
173  std::cout<<"phiwidth "<<phiwidth<<std::endl;
174  std::cout<<"OneMinusE1x5E5x5 "<<OneMinusE1x5E5x5<<std::endl;
175  std::cout<<"PreShowerOverRaw "<<PreShowerOverRaw<<std::endl;
176 */
177  bindVariables();
178 // double result= fmvaReader[GetMVABin(nPV,eta,pt)]->EvaluateMVA("BDT");
179  double result= fmvaReader[0]->EvaluateMVA("BDT");
180 // double result = tmvaReader_->EvaluateMVA("BDT");
181  return result;
182 }
float sigmaIphiIphi() const
Definition: GsfElectron.h:403
bool isAvailable() const
Definition: Ref.h:614
virtual double p() const
magnitude of momentum vector
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
float eSuperClusterOverP() const
Definition: GsfElectron.h:243
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
math::XYZVectorF trackMomentumAtVtx() const
Definition: GsfElectron.h:289
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
float fbrem() const
Definition: GsfElectron.h:684
virtual double eta() const
momentum pseudorapidity
virtual double pt() const
transverse momentum
TrackRef closestCtfTrackRef() const
Definition: GsfElectron.h:199
float deltaEtaSuperClusterTrackAtVtx() const
Definition: GsfElectron.h:247
float sigmaIetaIeta() const
Definition: GsfElectron.h:402
virtual SuperClusterRef superCluster() const
reference to a SuperCluster
Definition: GsfElectron.h:182
float deltaPhiSuperClusterTrackAtVtx() const
Definition: GsfElectron.h:250
tuple result
Definition: query.py:137
float eEleClusterOverPout() const
Definition: GsfElectron.h:246
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:242
float hcalOverEcalBc() const
Definition: GsfElectron.h:414
std::vector< TMVA::Reader * > fmvaReader
T const * product() const
Definition: Handle.h:81
float deltaEtaEleClusterTrackAtCalo() const
Definition: GsfElectron.h:249
float e1x5() const
Definition: GsfElectron.h:404
float ecalEnergy() const
Definition: GsfElectron.h:771
math::XYZVectorF trackMomentumAtEleClus() const
Definition: GsfElectron.h:292
float e5x5() const
Definition: GsfElectron.h:406
float r9() const
Definition: GsfElectron.h:407
float deltaEtaSeedClusterTrackAtCalo() const
Definition: GsfElectron.h:248
edm::EDGetTokenT< reco::VertexCollection > vtxCollection
float sigmaEtaEta() const
Definition: GsfElectron.h:401
virtual GsfTrackRef gsfTrack() const
reference to a GsfTrack
Definition: GsfElectron.h:183
tuple log
Definition: cmsBatch.py:347

Member Data Documentation

const Configuration SoftElectronMVAEstimator::cfg_
private

Definition at line 27 of file SoftElectronMVAEstimator.h.

Referenced by mva(), and SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::DeltaEtaTrackEcalSeed
private

Definition at line 36 of file SoftElectronMVAEstimator.h.

Referenced by mva(), and SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::deta
private

Definition at line 43 of file SoftElectronMVAEstimator.h.

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

Float_t SoftElectronMVAEstimator::detacalo
private

Definition at line 45 of file SoftElectronMVAEstimator.h.

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

Float_t SoftElectronMVAEstimator::dphi
private

Definition at line 44 of file SoftElectronMVAEstimator.h.

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

Float_t SoftElectronMVAEstimator::EBremOverDeltaP
private

Definition at line 34 of file SoftElectronMVAEstimator.h.

Referenced by mva(), and SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::eleEoPout
private

Definition at line 54 of file SoftElectronMVAEstimator.h.

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

Float_t SoftElectronMVAEstimator::eta
private
Float_t SoftElectronMVAEstimator::etawidth
private

Definition at line 48 of file SoftElectronMVAEstimator.h.

Referenced by mva(), and SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::EtotOvePin
private

Definition at line 33 of file SoftElectronMVAEstimator.h.

Referenced by mva(), and SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::fbrem
private

Definition at line 32 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 39 of file SoftElectronMVAEstimator.h.

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

Float_t SoftElectronMVAEstimator::HoE
private

Definition at line 52 of file SoftElectronMVAEstimator.h.

Referenced by mva(), and SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::IoEmIoP
private

Definition at line 58 of file SoftElectronMVAEstimator.h.

Referenced by mva(), and SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::kfchi2
private

Definition at line 37 of file SoftElectronMVAEstimator.h.

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

Float_t SoftElectronMVAEstimator::kfhits
private

Definition at line 38 of file SoftElectronMVAEstimator.h.

Referenced by mva(), and SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::logSigmaEtaEta
private

Definition at line 35 of file SoftElectronMVAEstimator.h.

Referenced by mva(), and SoftElectronMVAEstimator().

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

Definition at line 28 of file SoftElectronMVAEstimator.h.

Float_t SoftElectronMVAEstimator::nPV
private

Definition at line 65 of file SoftElectronMVAEstimator.h.

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

Float_t SoftElectronMVAEstimator::OneMinusE1x5E5x5
private

Definition at line 50 of file SoftElectronMVAEstimator.h.

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

Float_t SoftElectronMVAEstimator::phiwidth
private

Definition at line 49 of file SoftElectronMVAEstimator.h.

Referenced by mva(), and SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::PreShowerOverRaw
private

Definition at line 59 of file SoftElectronMVAEstimator.h.

Referenced by mva(), and SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::pt
private
Float_t SoftElectronMVAEstimator::R9
private

Definition at line 57 of file SoftElectronMVAEstimator.h.

Referenced by mva(), and SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::see
private

Definition at line 47 of file SoftElectronMVAEstimator.h.

Referenced by mva(), and SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::SigmaPtOverPt
private

Definition at line 40 of file SoftElectronMVAEstimator.h.

Referenced by mva(), and SoftElectronMVAEstimator().

Float_t SoftElectronMVAEstimator::spp
private

Definition at line 56 of file SoftElectronMVAEstimator.h.

Referenced by mva(), and SoftElectronMVAEstimator().

TMVA::Reader* SoftElectronMVAEstimator::tmvaReader_
private

Definition at line 30 of file SoftElectronMVAEstimator.h.

Referenced by SoftElectronMVAEstimator().