CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ElectronMVAEstimator.cc
Go to the documentation of this file.
7 
9  cfg_{}
10 {}
11 
13  cfg_{}
14 {
15  tmvaReader_ = new TMVA::Reader("!Color:Silent");
16  tmvaReader_->AddVariable("fbrem",&fbrem);
17  tmvaReader_->AddVariable("detain", &detain);
18  tmvaReader_->AddVariable("dphiin", &dphiin);
19  tmvaReader_->AddVariable("sieie", &sieie);
20  tmvaReader_->AddVariable("hoe", &hoe);
21  tmvaReader_->AddVariable("eop", &eop);
22  tmvaReader_->AddVariable("e1x5e5x5", &e1x5e5x5);
23  tmvaReader_->AddVariable("eleopout", &eleopout);
24  tmvaReader_->AddVariable("detaeleout", &detaeleout);
25  tmvaReader_->AddVariable("kfchi2", &kfchi2);
26  tmvaReader_->AddVariable("kfhits", &mykfhits);
27  tmvaReader_->AddVariable("mishits",&mymishits);
28  tmvaReader_->AddVariable("dist", &absdist);
29  tmvaReader_->AddVariable("dcot", &absdcot);
30  tmvaReader_->AddVariable("nvtx", &myNvtx);
31 
32  tmvaReader_->AddSpectator("eta",&eta);
33  tmvaReader_->AddSpectator("pt",&pt);
34  tmvaReader_->AddSpectator("ecalseed",&ecalseed);
35 
36  // Taken from Daniele (his mail from the 30/11)
37  // tmvaReader_->BookMVA("BDTSimpleCat","../Training/weights_Root527b_3Depth_DanVarConvRej_2PtBins_10Pt_800TPrune5_Min100Events_NoBjets_half/TMVA_BDTSimpleCat.weights.xm");
38  // training of the 7/12 with Nvtx added
39  tmvaReader_->BookMVA("BDTSimpleCat",fileName.c_str());
40 }
41 
43  std::vector<std::string> weightsfiles;
44  std::string path_mvaWeightFileEleID;
45  for(unsigned ifile=0 ; ifile < cfg_.vweightsfiles.size() ; ++ifile) {
46  path_mvaWeightFileEleID = edm::FileInPath ( cfg_.vweightsfiles[ifile].c_str() ).fullPath();
47  weightsfiles.push_back(path_mvaWeightFileEleID);
48  }
49  tmvaReader_ = new TMVA::Reader("!Color:Silent");
50  tmvaReader_->AddVariable("fbrem",&fbrem);
51  tmvaReader_->AddVariable("detain", &detain);
52  tmvaReader_->AddVariable("dphiin", &dphiin);
53  tmvaReader_->AddVariable("sieie", &sieie);
54  tmvaReader_->AddVariable("hoe", &hoe);
55  tmvaReader_->AddVariable("eop", &eop);
56  tmvaReader_->AddVariable("e1x5e5x5", &e1x5e5x5);
57  tmvaReader_->AddVariable("eleopout", &eleopout);
58  tmvaReader_->AddVariable("detaeleout", &detaeleout);
59  tmvaReader_->AddVariable("kfchi2", &kfchi2);
60  tmvaReader_->AddVariable("kfhits", &mykfhits);
61  tmvaReader_->AddVariable("mishits",&mymishits);
62  tmvaReader_->AddVariable("dist", &absdist);
63  tmvaReader_->AddVariable("dcot", &absdcot);
64  tmvaReader_->AddVariable("nvtx", &myNvtx);
65 
66  tmvaReader_->AddSpectator("eta",&eta);
67  tmvaReader_->AddSpectator("pt",&pt);
68  tmvaReader_->AddSpectator("ecalseed",&ecalseed);
69 
70  // Taken from Daniele (his mail from the 30/11)
71  // tmvaReader_->BookMVA("BDTSimpleCat","../Training/weights_Root527b_3Depth_DanVarConvRej_2PtBins_10Pt_800TPrune5_Min100Events_NoBjets_half/TMVA_BDTSimpleCat.weights.xm");
72  // training of the 7/12 with Nvtx added
73 
74  tmvaReader_->BookMVA("BDTSimpleCat",weightsfiles[0]);
75 }
76 
77 double ElectronMVAEstimator::mva(const reco::GsfElectron& myElectron, int nvertices ) {
78  fbrem = myElectron.fbrem();
81  sieie = myElectron.sigmaIetaIeta();
82  hoe = myElectron.hcalOverEcal();
83  eop = myElectron.eSuperClusterOverP();
84  e1x5e5x5 = (myElectron.e5x5()) !=0. ? 1.-(myElectron.e1x5()/myElectron.e5x5()) : -1. ;
85  eleopout = myElectron.eEleClusterOverPout();
87 
88  bool validKF= false;
89 
90  reco::TrackRef myTrackRef = myElectron.closestCtfTrackRef();
91  validKF = (myTrackRef.isAvailable());
92  validKF = (myTrackRef.isNonnull());
93 
94  kfchi2 = (validKF) ? myTrackRef->normalizedChi2() : 0 ;
95  kfhits = (validKF) ? myTrackRef->hitPattern().trackerLayersWithMeasurement() : -1.;
96  dist = myElectron.convDist();
97  dcot = myElectron.convDcot();
98  eta = myElectron.eta();
99  pt = myElectron.pt();
100 
101  mishits = myElectron.gsfTrack()->hitPattern().numberOfLostHits(reco::HitPattern::MISSING_INNER_HITS);
102  ecalseed = myElectron.ecalDrivenSeed();
103 
104  Nvtx = nvertices;
105 
106  bindVariables();
107  double result = tmvaReader_->EvaluateMVA("BDTSimpleCat");
108 //
109 // std::cout << "fbrem" <<fbrem << std::endl;
110 // std::cout << "detain"<< detain << std::endl;
111 // std::cout << "dphiin"<< dphiin << std::endl;
112 // std::cout << "sieie"<< sieie << std::endl;
113 // std::cout << "hoe"<< hoe << std::endl;
114 // std::cout << "eop"<< eop << std::endl;
115 // std::cout << "e1x5e5x5"<< e1x5e5x5 << std::endl;
116 // std::cout << "eleopout"<< eleopout << std::endl;
117 // std::cout << "detaeleout"<< detaeleout << std::endl;
118 // std::cout << "kfchi2"<< kfchi2 << std::endl;
119 // std::cout << "kfhits"<< mykfhits << std::endl;
120 // std::cout << "mishits"<<mymishits << std::endl;
121 // std::cout << "dist"<< absdist << std::endl;
122 // std::cout << "dcot"<< absdcot << std::endl;
123 //
124 // std::cout << "eta"<<eta << std::endl;
125 // std::cout << "pt"<<pt << std::endl;
126 // std::cout << "ecalseed"<<ecalseed << std::endl;
127 //
128 // std::cout << " MVA " << result << std::endl;
129  return result;
130 }
131 
132 
134  if(fbrem < -1.)
135  fbrem = -1.;
136 
137  detain = fabs(detain);
138  if(detain > 0.06)
139  detain = 0.06;
140 
141 
142  dphiin = fabs(dphiin);
143  if(dphiin > 0.6)
144  dphiin = 0.6;
145 
146 
147  if(eop > 20.)
148  eop = 20.;
149 
150 
151  if(eleopout > 20.)
152  eleopout = 20;
153 
154  detaeleout = fabs(detaeleout);
155  if(detaeleout > 0.2)
156  detaeleout = 0.2;
157 
158  mykfhits = float(kfhits);
159  mymishits = float(mishits);
160 
161  if(kfchi2 < 0.)
162  kfchi2 = 0.;
163 
164  if(kfchi2 > 15.)
165  kfchi2 = 15.;
166 
167 
168  if(e1x5e5x5 < -1.)
169  e1x5e5x5 = -1;
170 
171  if(e1x5e5x5 > 2.)
172  e1x5e5x5 = 2.;
173 
174 
175  if(dist > 15.)
176  dist = 15.;
177  if(dist < -15.)
178  dist = -15.;
179 
180  if(dcot > 3.)
181  dcot = 3.;
182  if(dcot < -3.)
183  dcot = -3.;
184 
185  absdist = fabs(dist);
186  absdcot = fabs(dcot);
187  myNvtx = float(Nvtx);
188 
189 }
bool isAvailable() const
Definition: Ref.h:614
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
virtual float pt() const
transverse momentum
float eSuperClusterOverP() const
Definition: GsfElectron.h:243
float fbrem() const
Definition: GsfElectron.h:684
T eta() const
float convDist() const
Definition: GsfElectron.h:539
TrackRef closestCtfTrackRef() const
Definition: GsfElectron.h:199
float convDcot() const
Definition: GsfElectron.h:540
float deltaEtaSuperClusterTrackAtVtx() const
Definition: GsfElectron.h:247
float sigmaIetaIeta() const
Definition: GsfElectron.h:402
virtual float eta() const
momentum pseudorapidity
float deltaPhiSuperClusterTrackAtVtx() const
Definition: GsfElectron.h:250
tuple result
Definition: query.py:137
const Configuration cfg_
float hcalOverEcal() const
Definition: GsfElectron.h:410
float eEleClusterOverPout() const
Definition: GsfElectron.h:246
float deltaEtaEleClusterTrackAtCalo() const
Definition: GsfElectron.h:249
float e1x5() const
Definition: GsfElectron.h:404
std::vector< std::string > vweightsfiles
float e5x5() const
Definition: GsfElectron.h:406
double mva(const reco::GsfElectron &myElectron, int nvertices=0)
virtual GsfTrackRef gsfTrack() const
reference to a GsfTrack
Definition: GsfElectron.h:183
bool ecalDrivenSeed() const
Definition: GsfElectron.h:186