ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Utils/src/MVATools.cc
Revision: 1.20
Committed: Fri Oct 26 19:23:04 2012 UTC (12 years, 6 months ago) by fabstoec
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_029c, Mit_029b, Mit_029a
Changes since 1.19: +2 -1 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 // $Id: MVATools.cc,v 1.19 2012/10/13 20:42:20 mingyang Exp $
2
3 #include "MitPhysics/Utils/interface/PhotonTools.h"
4 #include "MitPhysics/Utils/interface/MVATools.h"
5 #include "MitPhysics/Utils/interface/ElectronTools.h"
6 #include "MitPhysics/Utils/interface/IsolationTools.h"
7 #include "MitAna/DataTree/interface/PFCandidateCol.h"
8 #include "MitAna/DataTree/interface/StableData.h"
9 #include <TMath.h>
10 #include <TFile.h>
11 #include <TRandom3.h>
12 #include <TSystem.h>
13 #include "TMVA/Tools.h"//MVA
14 #include "TMVA/Reader.h"//MVA
15
16
17 ClassImp(mithep::MVATools)
18
19 using namespace mithep;
20
21
22 //--------------------------------------------------------------------------------------------------
23 MVATools::MVATools():
24 fReaderEndcap(0),
25 fReaderBarrel(0),
26
27 fMVAType (MVATools::kNone)
28
29 // ------------------------------------------------------------------------------
30 // fab: These guys should all go away....
31 //MVA Variables v4
32 // HoE(0),
33 // covIEtaIEta(0),
34 // tIso1abs(0),
35 // tIso3abs(0),
36 // tIso2abs(0),
37 // R9(0),
38
39 // absIsoEcal(0),
40 // absIsoHcal(0),
41 // RelEMax(0),
42 // RelETop(0),
43 // RelEBottom(0),
44 // RelELeft(0),
45 // RelERight(0),
46 // RelE2x5Max(0),
47 // RelE2x5Top(0),
48 // RelE2x5Bottom(0),
49 // RelE2x5Left(0),
50 // RelE2x5Right(0),
51 // RelE5x5(0),
52
53 // EtaWidth(0),
54 // PhiWidth(0),
55 // CoviEtaiPhi(0),
56 // CoviPhiiPhi(0),
57
58 // NVertexes(0),
59 // RelPreshowerEnergy(0),
60
61 // //MVA v2 and v1
62 // RelIsoEcal(0),
63 // RelIsoHcal(0),
64 // tIso1(0),
65 // tIso3(0),
66 // tIso2(0),
67 // ScEta(0.)
68
69 {
70 // Constructor.
71 }
72
73 //--------------------------------------------------------------------------------------------------
74 void MVATools::InitializeMVA(MVATools::IdMVAType type) {
75
76 fMVAType = type;
77
78 if (fReaderEndcap) delete fReaderEndcap;
79 if (fReaderBarrel) delete fReaderBarrel;
80
81 // no MVA needed if none requested
82 if( type == kNone ) {
83 return;
84 }
85
86 fReaderEndcap = new TMVA::Reader( "!Color:!Silent:Error" );
87 fReaderBarrel = new TMVA::Reader( "!Color:!Silent:Error" );
88
89 TString BarrelWeights;
90 TString EndcapWeights;
91
92 varNames.resize(0);
93
94 switch (type) {
95
96 case k2011IdMVA_HZg:
97
98 EndcapWeights = (gSystem->Getenv("CMSSW_BASE")+
99 TString("/src/MitPhysics/data/")+
100 TString("PhotonId_lowPt_EE_BDTG.")+
101 TString("weights.xml"));
102 BarrelWeights = (gSystem->Getenv("CMSSW_BASE")+
103 TString("/src/MitPhysics/data/")+
104 TString("PhotonId_lowPt_EB_BDTG.")+
105 TString("weights.xml"));
106
107
108 varNames.push_back("sigieie");
109 varNames.push_back("covieip");
110 varNames.push_back("s4r" );
111 varNames.push_back("r9" );
112 varNames.push_back("sigeta" );
113 varNames.push_back("sigphi" );
114 varNames.push_back("pfgios" );
115 varNames.push_back("pfciso" );
116 varNames.push_back("rho" );
117 varNames.push_back("sceta" );
118 varNames.push_back("rawe" );
119
120 mvaVars.resize(varNames.size());
121
122 std::cout<<" Adding stuff here.... "<<std::endl;
123
124 for( unsigned int iV = 0; iV < mvaVars.size(); ++iV) {
125 mvaVarMapEB.insert( std::pair<std::string,unsigned int>(varNames[iV], iV) );
126 mvaVarMapEE.insert( std::pair<std::string,unsigned int>(varNames[iV], iV) );
127 }
128
129 std::cout<<" ... done "<<std::endl;
130
131 break;
132
133 case k2011IdMVA:
134
135 EndcapWeights = (gSystem->Getenv("CMSSW_BASE")+
136 TString("/src/MitPhysics/data/TMVAClassificationPhotonID_")+
137 TString("Endcap_PassPreSel_Variable_10_BDTnCuts2000_BDT.")+
138 TString("weights.xml"));
139 BarrelWeights = (gSystem->Getenv("CMSSW_BASE")+
140 TString("/src/MitPhysics/data/TMVAClassificationPhotonID_")+
141 TString("Barrel_PassPreSel_Variable_10_BDTnCuts2000_BDT.")+
142 TString("weights.xml"));
143
144 // set up the variable names
145 mvaVars.resize(12);
146 varNames.push_back("HoE" );
147 varNames.push_back("covIEtaIEta");
148 varNames.push_back("tIso1abs" );
149 varNames.push_back("tIso3abs" );
150 varNames.push_back("tIso2abs" );
151 varNames.push_back("R9" );
152 varNames.push_back("absIsoEcal" );
153 varNames.push_back("absIsoHcal" );
154 varNames.push_back("NVertexes" );
155 varNames.push_back("ScEta" );
156 varNames.push_back("EtaWidth" );
157 varNames.push_back("PhiWidth" );
158
159 for( unsigned int iV = 0; iV < mvaVars.size(); ++iV) {
160 mvaVarMapEB.insert( std::pair<std::string,unsigned int>(varNames[iV], iV) );
161 mvaVarMapEE.insert( std::pair<std::string,unsigned int>(varNames[iV], iV) );
162 }
163
164 break;
165
166 case k2012IdMVA:
167 case k2012IdMVA_globe:
168
169 EndcapWeights = (gSystem->Getenv("CMSSW_BASE")+
170 TString("/src/MitPhysics/data/")+
171 TString("2012ICHEP_PhotonID_Endcap_BDT.")+
172 TString("weights_PSCorr.xml"));
173 BarrelWeights = (gSystem->Getenv("CMSSW_BASE")+
174 TString("/src/MitPhysics/data/")+
175 TString("2012ICHEP_PhotonID_Barrel_BDT.")+
176 TString("weights.xml"));
177
178 mvaVars.resize(12);
179 varNames.push_back("ph.r9" );
180 varNames.push_back("ph.sigietaieta" );
181 varNames.push_back("ph.scetawidth" );
182 varNames.push_back("ph.scphiwidth" );
183 varNames.push_back("ph.idmva_CoviEtaiPhi" );
184 varNames.push_back("ph.idmva_s4ratio" );
185 varNames.push_back("ph.idmva_GammaIso" );
186 varNames.push_back("ph.idmva_ChargedIso_selvtx" );
187 varNames.push_back("ph.idmva_ChargedIso_worstvtx" );
188 varNames.push_back("ph.sceta" );
189 varNames.push_back("rho" );
190 varNames.push_back("ph.idmva_PsEffWidthSigmaRR" );
191
192 for( unsigned int iV = 0; iV < mvaVars.size() - 1; ++iV) {
193 mvaVarMapEB.insert( std::pair<std::string,unsigned int>(varNames[iV], iV) );
194 mvaVarMapEE.insert( std::pair<std::string,unsigned int>(varNames[iV], iV) );
195 }
196
197 // pre-shower only used for Endcaps
198 mvaVarMapEE.insert( std::pair<std::string,unsigned int> ( varNames[mvaVars.size() - 1], mvaVars.size() - 1) );
199
200 break;
201
202 default:
203 // no variables... better never called..
204 std::cerr<<" MVATools: Trying to initialize with unknown type."<<std::endl;
205 break;
206 }
207
208
209 // looping over both maps and adding Vars to BDT readers
210 for( unsigned int iV = 0; iV < varNames.size(); ++iV ){
211 std::map<std::string,unsigned int>::const_iterator it = mvaVarMapEB.find(varNames[iV]);
212 if ( it != mvaVarMapEB.end() )
213 fReaderBarrel -> AddVariable( (it->first).c_str(), &(mvaVars[it->second]));
214 it = mvaVarMapEE.find(varNames[iV]);
215 if ( it != mvaVarMapEE.end() )
216 fReaderEndcap -> AddVariable( (it->first).c_str(), &(mvaVars[it->second]));
217 }
218
219 fReaderEndcap->BookMVA("BDT method",EndcapWeights);
220 fReaderBarrel->BookMVA("BDT method",BarrelWeights);
221
222 assert(fReaderEndcap);
223 assert(fReaderBarrel);
224
225 }
226
227 // //--------------------------------------------------------------------------------------------------
228 // void MVATools::InitializeMVA(int VariableType, TString EndcapWeights,TString BarrelWeights) {
229
230 // if (fReaderEndcap) delete fReaderEndcap;
231 // if (fReaderBarrel) delete fReaderBarrel;
232
233 // fReaderEndcap = new TMVA::Reader( "!Color:!Silent:Error" );
234 // fReaderBarrel = new TMVA::Reader( "!Color:!Silent:Error" );
235
236 // TMVA::Reader *readers[2];
237 // readers[0] = fReaderEndcap;
238 // readers[1] = fReaderBarrel;
239
240 // for (UInt_t i=0; i<2; ++i) {
241
242 // if(VariableType==0||VariableType==1||VariableType==2){
243 // readers[i]->AddVariable( "HoE", &HoE );
244 // readers[i]->AddVariable( "covIEtaIEta", &covIEtaIEta );
245 // readers[i]->AddVariable( "tIso1", &tIso1 );
246 // readers[i]->AddVariable( "tIso3", &tIso3 );
247 // readers[i]->AddVariable( "tIso2", &tIso2 );
248 // readers[i]->AddVariable( "R9", &R9 );
249 // }
250
251 // if(VariableType==3||VariableType==4){
252 // readers[i]->AddVariable( "HoE", &HoE );
253 // readers[i]->AddVariable( "covIEtaIEta", &covIEtaIEta );
254 // readers[i]->AddVariable( "tIso1abs", &tIso1abs );
255 // readers[i]->AddVariable( "tIso3abs", &tIso3abs );
256 // readers[i]->AddVariable( "tIso2abs", &tIso2abs );
257 // readers[i]->AddVariable( "R9", &R9 );
258 // }
259
260 // if(VariableType==1||VariableType==2){
261 // readers[i]->AddVariable( "RelIsoEcal", &RelIsoEcal );
262 // readers[i]->AddVariable( "RelIsoHcal", &RelIsoHcal );
263 // readers[i]->AddVariable( "RelEMax", &RelEMax );
264 // readers[i]->AddVariable( "RelETop", &RelETop );
265 // readers[i]->AddVariable( "RelEBottom", &RelEBottom );
266 // readers[i]->AddVariable( "RelELeft", &RelELeft );
267 // readers[i]->AddVariable( "RelERight", &RelERight );
268 // readers[i]->AddVariable( "RelE2x5Max", &RelE2x5Max );
269 // readers[i]->AddVariable( "RelE2x5Top", &RelE2x5Top );
270 // readers[i]->AddVariable( "RelE2x5Bottom", &RelE2x5Bottom );
271 // readers[i]->AddVariable( "RelE2x5Left", &RelE2x5Left );
272 // readers[i]->AddVariable( "RelE2x5Right", &RelE2x5Right );
273 // readers[i]->AddVariable( "RelE5x5", &RelE5x5 );
274 // }
275
276 // if(VariableType==3||VariableType==4){
277 // readers[i]->AddVariable( "absIsoEcal", &absIsoEcal );
278 // readers[i]->AddVariable( "absIsoHcal", &absIsoHcal );
279 // readers[i]->AddVariable( "RelEMax", &RelEMax );
280 // readers[i]->AddVariable( "RelETop", &RelEBottom);
281 // readers[i]->AddVariable( "RelEBottom", &RelEBottom );
282 // readers[i]->AddVariable( "RelELeft", &RelELeft );
283 // readers[i]->AddVariable( "RelERight", &RelERight );
284 // readers[i]->AddVariable( "RelE2x5Max", &RelE2x5Max );
285 // readers[i]->AddVariable( "RelE2x5Top", &RelE2x5Top );
286 // readers[i]->AddVariable( "RelE2x5Bottom", &RelE2x5Bottom );
287 // readers[i]->AddVariable( "RelE2x5Left", &RelE2x5Left );
288 // readers[i]->AddVariable( "RelE2x5Right", &RelE2x5Right );
289 // readers[i]->AddVariable( "RelE5x5", &RelE5x5 );
290 // }
291
292 // if(VariableType==2||VariableType==3||VariableType==4){
293 // readers[i]->AddVariable( "EtaWidth", &EtaWidth );
294 // readers[i]->AddVariable( "PhiWidth", &PhiWidth );
295 // readers[i]->AddVariable( "CoviEtaiPhi", &CoviEtaiPhi );
296 // readers[i]->AddVariable( "CoviPhiiPhi", &CoviPhiiPhi );
297 // if(VariableType==4){
298 // readers[i]->AddVariable( "NVertexes", &NVertexes );
299 // }
300 // if(i==0){
301 // readers[i]->AddVariable( "RelPreshowerEnergy", &RelPreshowerEnergy );
302 // }
303 // }
304
305 // if(VariableType==6){
306 // readers[i]->AddVariable( "HoE", &HoE );
307 // readers[i]->AddVariable( "covIEtaIEta", &covIEtaIEta );
308 // readers[i]->AddVariable( "tIso1abs", &tIso1abs );
309 // readers[i]->AddVariable( "tIso3abs", &tIso3abs );
310 // readers[i]->AddVariable( "tIso2abs", &tIso2abs );
311 // readers[i]->AddVariable( "R9", &R9 );
312 // readers[i]->AddVariable( "absIsoEcal", &absIsoEcal );
313 // readers[i]->AddVariable( "absIsoHcal", &absIsoHcal );
314 // readers[i]->AddVariable( "RelE5x5", &RelE5x5 );
315 // readers[i]->AddVariable( "EtaWidth", &EtaWidth );
316 // readers[i]->AddVariable( "PhiWidth", &PhiWidth );
317 // readers[i]->AddVariable( "CoviEtaiPhi", &CoviEtaiPhi );
318 // readers[i]->AddVariable( "CoviPhiiPhi", &CoviPhiiPhi );
319 // readers[i]->AddVariable( "NVertexes", &NVertexes );
320 // if(i==0){
321 // readers[i]->AddVariable( "RelPreshowerEnergy", &RelPreshowerEnergy );
322 // }
323 // }
324
325 // if(VariableType==7){
326 // readers[i]->AddVariable( "HoE", &HoE );
327 // readers[i]->AddVariable( "covIEtaIEta", &covIEtaIEta );
328 // readers[i]->AddVariable( "tIso1abs", &tIso1abs );
329 // readers[i]->AddVariable( "tIso3abs", &tIso3abs );
330 // readers[i]->AddVariable( "tIso2abs", &tIso2abs );
331 // readers[i]->AddVariable( "R9", &R9 );
332 // readers[i]->AddVariable( "absIsoEcal", &absIsoEcal );
333 // readers[i]->AddVariable( "absIsoHcal", &absIsoHcal );
334 // readers[i]->AddVariable( "NVertexes", &NVertexes );
335 // readers[i]->AddVariable( "ScEta", &ScEta );
336 // }
337
338 // if(VariableType==10){
339 // readers[i]->AddVariable( "HoE", &HoE );
340 // readers[i]->AddVariable( "covIEtaIEta", &covIEtaIEta );
341 // readers[i]->AddVariable( "tIso1abs", &tIso1abs );
342 // readers[i]->AddVariable( "tIso3abs", &tIso3abs );
343 // readers[i]->AddVariable( "tIso2abs", &tIso2abs );
344 // readers[i]->AddVariable( "R9", &R9 );
345 // readers[i]->AddVariable( "absIsoEcal", &absIsoEcal );
346 // readers[i]->AddVariable( "absIsoHcal", &absIsoHcal );
347 // readers[i]->AddVariable( "NVertexes", &NVertexes );
348 // readers[i]->AddVariable( "ScEta", &ScEta );
349 // readers[i]->AddVariable( "EtaWidth", &EtaWidth );
350 // readers[i]->AddVariable( "PhiWidth", &PhiWidth );
351 // }
352
353 // if(VariableType==1201){
354 // /*readers[i]->AddVariable( "myphoton_pfchargedisogood03", &myphoton_pfchargedisogood03);
355 // readers[i]->AddVariable( "myphoton_pfchargedisobad03", &myphoton_pfchargedisobad03);
356 // readers[i]->AddVariable( "myphoton_pfphotoniso03", &myphoton_pfphotoniso03 );
357 // readers[i]->AddVariable( "myphoton_sieie", &myphoton_sieie );
358 // readers[i]->AddVariable( "myphoton_sieip", &myphoton_sieip );
359 // readers[i]->AddVariable( "myphoton_etawidth", &myphoton_etawidth );
360 // readers[i]->AddVariable( "myphoton_phiwidth", &myphoton_phiwidth );
361 // readers[i]->AddVariable( "myphoton_r9", &myphoton_r9 );
362 // readers[i]->AddVariable( "myphoton_s4ratio", &myphoton_s4ratio );
363 // readers[i]->AddVariable( "myphoton_SCeta", &myphoton_SCeta );
364 // readers[i]->AddVariable( "event_rho", &event_rho );
365 // if(i==0){
366 // readers[i]->AddVariable( "myphoton_ESEffSigmaRR", &myphoton_ESEffSigmaRR);
367 // }*/
368 // readers[i]->AddVariable( "ph.r9", &myphoton_r9 );
369 // readers[i]->AddVariable( "ph.sigietaieta", &myphoton_sieie );
370 // readers[i]->AddVariable( "ph.scetawidth", &myphoton_etawidth );
371 // readers[i]->AddVariable( "ph.scphiwidth", &myphoton_phiwidth );
372 // readers[i]->AddVariable( "ph.idmva_CoviEtaiPhi", &myphoton_sieip );
373 // readers[i]->AddVariable( "ph.idmva_s4ratio", &myphoton_s4ratio );
374 // readers[i]->AddVariable( "ph.idmva_GammaIso", &myphoton_pfphotoniso03 );
375 // readers[i]->AddVariable( "ph.idmva_ChargedIso_selvtx", &myphoton_pfchargedisogood03);
376 // readers[i]->AddVariable( "ph.idmva_ChargedIso_worstvtx", &myphoton_pfchargedisobad03);
377 // readers[i]->AddVariable( "ph.sceta", &myphoton_SCeta );
378 // readers[i]->AddVariable( "rho", &event_rho );
379 // if(i==0){
380 // //readers[i]->AddVariable( "1.00023*ph.idmva_PsEffWidthSigmaRR + 0.0913", &myphoton_ESEffSigmaRR);
381 // readers[i]->AddVariable( "ph.idmva_PsEffWidthSigmaRR", &myphoton_ESEffSigmaRR);
382 // }
383 // }
384
385 // }
386
387 // fReaderEndcap->BookMVA("BDT method",EndcapWeights);
388 // fReaderBarrel->BookMVA("BDT method",BarrelWeights);
389
390 // assert(fReaderEndcap);
391 // assert(fReaderBarrel);
392
393 // }
394
395 // *** REMOVED THIS COMPLETELY. If a module wants to cut on BDT, it should 1,) compute the BDT value (using GetMVAbdtValue(...) ) and then make the cut itself...
396
397 // Bool_t MVATools::PassMVASelection(const Photon* p,const Vertex* vtx,const TrackCol* trackCol,const VertexCol* vtxCol,Double_t _tRho,Float_t bdtCutBarrel, Float_t bdtCutEndcap, const ElectronCol* els, Bool_t applyElectronVeto) {
398
399 // //initilize the bool value
400 // PassMVA=kFALSE;
401
402 // Float_t photon_bdt = MVATools::GetMVAbdtValue_2011(p,vtx,trackCol,vtxCol, _tRho, els, applyElectronVeto);
403
404 // if (isbarrel) {
405 // if(photon_bdt>bdtCutBarrel){
406 // PassMVA=kTRUE;
407 // }
408 // }
409 // else {
410 // if(photon_bdt>bdtCutEndcap){
411 // PassMVA=kTRUE;
412 // }
413 // }
414 // return PassMVA;
415 // }
416
417 // //---------------------------------------------------------------------------------
418 // Int_t MVATools::PassElectronVetoInt(const Photon* p, const ElectronCol* els) {
419
420 // // these values are taken from the H2GGlobe code... (actually from Marco/s mail)
421 // float cic4_allcuts_temp_sublead[] = {
422 // 3.8, 2.2, 1.77, 1.29,
423 // 11.7, 3.4, 3.9, 1.84,
424 // 3.5, 2.2, 2.3, 1.45,
425 // 0.0106, 0.0097, 0.028, 0.027,
426 // 0.082, 0.062, 0.065, 0.048,
427 // 0.94, 0.36, 0.94, 0.32,
428 // 1., 0.062, 0.97, 0.97,
429 // 1.5, 1.5, 1.5, 1.5 }; // the last line is PixelmatchVeto and un-used
430
431 // //initilize the bool value
432 // PassElecVetoInt=0;
433
434 // dRTrack = PhotonTools::ElectronVetoCiC(p, els);
435
436 // ScEta_MVA=p->SCluster()->Eta();
437
438 // isbarrel = (fabs(ScEta_MVA)<1.4442);
439
440 // R9 = p->R9();
441 // //R9 = p->E33()/p->SCluster()->RawEnergy();
442
443 // // check which category it is ...
444 // _tCat = 1;
445 // if ( !isbarrel ) _tCat = 3;
446 // if ( R9 < 0.94 ) _tCat++;
447
448 // //Electron Veto
449 // if(dRTrack > cic4_allcuts_temp_sublead[_tCat-1+6*4]){
450 // PassElecVetoInt=1;
451 // }
452
453 // return PassElecVetoInt;
454
455 // }
456
457 //--------------------------------------------------------------------------------------------------
458
459
460 Double_t MVATools::GetMVAbdtValue(const Photon* p, const Vertex* vtx, const TrackCol* trackCol, const VertexCol* vtxCol, Double_t _tRho, const PFCandidateCol *fPFCands, const ElectronCol* els, Bool_t applyElectronVeto) {
461
462 // if there's no reader, or the type is kNone, return the default values of -99.
463 if( ( !fReaderBarrel || !fReaderEndcap ) || fMVAType == kNone ) return -99.;
464
465 // we compute the variable names... make sure no confilcts when adding new variables...
466
467 // check if it's a Barrel or EE photon
468 bool isBarrel = ( p->SCluster()->AbsEta() < 1.5 );
469
470 std::map<std::string,unsigned int>* theVars = ( isBarrel ? &mvaVarMapEB : &mvaVarMapEE );
471
472 // loop over all the variables in the map... and keep count (to make sure we have filled all variables)
473 unsigned int varCounter = 0;
474 for( std::map<std::string,unsigned int>::const_iterator iV = theVars->begin(); iV != theVars->end(); ++iV ) {
475
476 TString theVarName = TString(iV->first);
477 float* theVarValue = &(mvaVars[iV->second]); // pointer to the variable...
478
479 if(
480 !theVarName.CompareTo("HoE")
481 ) {
482 (*theVarValue) = p->HadOverEm();
483 varCounter++;
484 } else if (
485 !theVarName.CompareTo("covIEtaIEta") || !theVarName.CompareTo("ph.sigietaieta") || !theVarName.CompareTo("sigieie")
486 ) {
487 (*theVarValue) = p->CoviEtaiEta();
488 varCounter++;
489 } else if (
490 !theVarName.CompareTo("R9") || !theVarName.CompareTo("ph.r9") || !theVarName.CompareTo("r9")
491 ) {
492 (*theVarValue) = p->R9();
493 varCounter++;
494 } else if (
495 !theVarName.CompareTo("ScEta") || !theVarName.CompareTo("ph.sceta") || !theVarName.CompareTo("sceta")
496 ) {
497 (*theVarValue) = p->SCluster()->Eta();
498 varCounter++;
499 } else if (
500 !theVarName.CompareTo("rho")
501 ) {
502 (*theVarValue) = _tRho;
503 varCounter++;
504 } else if (
505 !theVarName.CompareTo("tIso1abs")
506 ) {
507 double _ecalIso3 = p->EcalRecHitIsoDr03();
508 double _hcalIso4 = p->HcalTowerSumEtDr04();
509 double _trackIso1 = IsolationTools::CiCTrackIsolation(p,vtx, 0.3, 0.02, 0.0, 0.0, 0.1, 1.0, trackCol, NULL, NULL, (!applyElectronVeto ? els : NULL) );//Question Ming:whyfPV->At(0) instead of selected vertex using ranking method?
510 (*theVarValue) = _ecalIso3+_hcalIso4+_trackIso1 - 0.17*_tRho;
511 varCounter++;
512 } else if (
513 !theVarName.CompareTo("tIso2abs")
514 ) {
515 double _ecalIso4 = p->EcalRecHitIsoDr04();
516 double _hcalIso4 = p->HcalTowerSumEtDr04();
517 unsigned int wVtxInd = 0;
518 double _trackIso2 = IsolationTools::CiCTrackIsolation(p,vtx, 0.4, 0.02, 0.0, 0.0, 0.1, 1.0, trackCol, &wVtxInd,vtxCol, (!applyElectronVeto ? els : NULL) );
519 (*theVarValue) = _ecalIso4+_hcalIso4+_trackIso2 - 0.52*_tRho;
520 varCounter++;
521 } else if (
522 !theVarName.CompareTo("tIso3abs")
523 ) {
524 (*theVarValue) = IsolationTools::CiCTrackIsolation(p,vtx, 0.3, 0.02, 0.0, 0.0, 0.1, 1.0, trackCol, NULL, NULL, (!applyElectronVeto ? els : NULL) );
525 varCounter++;
526 } else if (
527 !theVarName.CompareTo("absIsoEcal")
528 ) {
529 double _ecalIso3 = p->EcalRecHitIsoDr03();
530 (*theVarValue) = (_ecalIso3-0.17*_tRho);
531 varCounter++;
532 } else if (
533 !theVarName.CompareTo("absIsoHcal")
534 ) {
535 double _hcalIso4 = p->HcalTowerSumEtDr04();
536 (*theVarValue) = (_hcalIso4-0.17*_tRho);
537 varCounter++;
538 } else if (
539 !theVarName.CompareTo("NVertexes")
540 ) {
541
542 (*theVarValue) = vtxCol->GetEntries();
543 varCounter++;
544 } else if (
545 !theVarName.CompareTo("EtaWidth") || !theVarName.CompareTo("ph.scetawidth") || !theVarName.CompareTo("sigeta")
546 ) {
547 (*theVarValue) = p->EtaWidth();
548 varCounter++;
549 } else if (
550 !theVarName.CompareTo("PhiWidth") || !theVarName.CompareTo("ph.scphiwidth") || !theVarName.CompareTo("sigphi")
551 ) {
552 (*theVarValue) = p->PhiWidth();
553 varCounter++;
554
555 } else if (
556 !theVarName.CompareTo("ph.idmva_CoviEtaiPhi") || !theVarName.CompareTo("covieip")
557 ) {
558 (*theVarValue) = p->SCluster()->Seed()->CoviEtaiPhi();
559 varCounter++;
560 } else if (
561 !theVarName.CompareTo("ph.idmva_s4ratio") || !theVarName.CompareTo("s4r")
562 ) {
563 (*theVarValue) = p->S4Ratio();
564 //(*theVarValue) = p->SCluster()->Seed()->E2x2()/p->E55();
565 varCounter++;
566 } else if (
567 !theVarName.CompareTo("ph.idmva_GammaIso") || !theVarName.CompareTo("pfgiso")
568 ) {
569 (*theVarValue) = IsolationTools::PFGammaIsolation(p,0.3,0,fPFCands);
570 varCounter++;
571 } else if (
572 !theVarName.CompareTo("ph.idmva_ChargedIso_selvtx") || !theVarName.CompareTo("pfciso")
573 ) {
574 (*theVarValue) = IsolationTools::PFChargedIsolation(p,vtx,0.3,0,fPFCands);
575 varCounter++;
576 } else if (
577 !theVarName.CompareTo("ph.idmva_ChargedIso_worstvtx")
578 ) {
579 unsigned int wVtxInd = 0;
580 (*theVarValue) = IsolationTools::PFChargedIsolation(p,vtx,0.3,0,fPFCands,&wVtxInd,vtxCol);
581 varCounter++;
582 } else if (
583 !theVarName.CompareTo("ph.idmva_PsEffWidthSigmaRR")
584 ) {
585 (*theVarValue) = p->EffSigmaRR();
586 varCounter++;
587 } else if (
588 !theVarName.CompareTo("rawe")
589 ) {
590 (*theVarValue) = p->SCluster()->RawEnergy();
591 varCounter++;
592 } else {
593 // a variable is not know... copmplain!
594 std::cerr<<" ERROR: MVA Evaluation called with unknown variable name >"<<theVarName<<">."<<std::endl;
595 }
596 }
597
598 // now all the variables should be filled... check!
599 if( varCounter != theVars->size() )
600 std::cerr<<" ERROR: MVA Evaludation called and not all variables are filled."<<std::endl;
601
602 // we're ready to compute the MVA value
603 TMVA::Reader* reader = NULL;
604 if (isBarrel)
605 reader = fReaderBarrel;
606 else
607 reader = fReaderEndcap;
608
609 assert(reader);
610
611 return (reader->EvaluateMVA("BDT method"));
612 }
613
614 // Float_t MVATools::GetMVAbdtValue_2012_globe(const Photon* p,const Vertex* vtx,const TrackCol* trackCol,const VertexCol* vtxCol,Double_t _tRho, const PFCandidateCol *fPFCands,const ElectronCol* els,Bool_t applyElectronVeto) {
615
616 // //get the variables used to compute MVA variables
617 // ecalIso3 = p->EcalRecHitIsoDr03();
618 // ecalIso4 = p->EcalRecHitIsoDr04();
619 // hcalIso4 = p->HcalTowerSumEtDr04();
620
621 // wVtxInd = 0;
622
623 // trackIso1 = IsolationTools::CiCTrackIsolation(p,vtx, 0.3, 0.02, 0.0, 0.0, 0.1, 1.0, trackCol, NULL, NULL, (!applyElectronVeto ? els : NULL) );//Question Ming:whyfPV->At(0) instead of selected vertex using ranking method?
624
625 // // track iso worst vtx
626 // trackIso2 = IsolationTools::CiCTrackIsolation(p,vtx, 0.4, 0.02, 0.0, 0.0, 0.1, 1.0, trackCol, &wVtxInd,vtxCol, (!applyElectronVeto ? els : NULL) );
627
628 // combIso1 = ecalIso3+hcalIso4+trackIso1 - 0.17*_tRho;
629 // combIso2 = ecalIso4+hcalIso4+trackIso2 - 0.52*_tRho;
630
631 // RawEnergy = p->SCluster()->RawEnergy();
632
633 // ScEta = p->SCluster()->Eta();
634
635 // //mva varialbes v1 and v2
636 // tIso1 = (combIso1) *50./p->Et();
637 // tIso3 = (trackIso1)*50./p->Et();
638 // tIso2 = (combIso2) *50./(p->MomVtx(vtxCol->At(wVtxInd)->Position()).Pt());
639 // RelIsoEcal=(ecalIso3-0.17*_tRho)/p->Et();
640 // RelIsoHcal=(hcalIso4-0.17*_tRho)/p->Et();
641
642 // //compute mva variables for v3
643 // HoE = p->HadOverEm();
644 // covIEtaIEta = p->CoviEtaiEta();
645 // tIso1abs = combIso1;
646 // tIso3abs = trackIso1;
647 // tIso2abs = combIso2;
648 // R9 = p->R9();
649
650 // absIsoEcal=(ecalIso3-0.17*_tRho);
651 // absIsoHcal=(hcalIso4-0.17*_tRho);
652 // RelEMax=p->SCluster()->Seed()->EMax()/RawEnergy;
653 // RelETop=p->SCluster()->Seed()->ETop()/RawEnergy;
654 // RelEBottom=p->SCluster()->Seed()->EBottom()/RawEnergy;
655 // RelELeft=p->SCluster()->Seed()->ELeft()/RawEnergy;
656 // RelERight=p->SCluster()->Seed()->ERight()/RawEnergy;
657 // RelE2x5Max=p->SCluster()->Seed()->E2x5Max()/RawEnergy;
658 // RelE2x5Top=p->SCluster()->Seed()->E2x5Top()/RawEnergy;
659 // RelE2x5Bottom=p->SCluster()->Seed()->E2x5Bottom()/RawEnergy;
660 // RelE2x5Left=p->SCluster()->Seed()->E2x5Left()/RawEnergy;
661 // RelE2x5Right=p->SCluster()->Seed()->E2x5Right()/RawEnergy;
662 // RelE5x5=p->SCluster()->Seed()->E5x5()/RawEnergy;
663
664 // EtaWidth=p->EtaWidth();
665 // PhiWidth=p->PhiWidth();
666 // CoviEtaiPhi=p->SCluster()->Seed()->CoviEtaiPhi();
667 // CoviPhiiPhi=p->SCluster()->Seed()->CoviPhiiPhi();
668
669 // RelPreshowerEnergy=p->SCluster()->PreshowerEnergy()/RawEnergy;
670 // NVertexes=vtxCol->GetEntries();
671
672 // //spectator variables
673 // Pt_MVA=p->Pt();
674 // ScEta_MVA=p->SCluster()->Eta();
675
676 // //
677
678 // isbarrel = (fabs(ScEta_MVA)<1.4442);
679
680 // //variable 1201
681 // myphoton_pfchargedisogood03=IsolationTools::PFChargedIsolation(p,vtx,0.3,0,fPFCands);
682 // myphoton_pfchargedisobad03=IsolationTools::PFChargedIsolation(p,vtx,0.3,0,fPFCands,&wVtxInd,vtxCol);
683 // myphoton_pfphotoniso03=IsolationTools::PFGammaIsolation(p,0.3,0,fPFCands);
684 // myphoton_sieie=covIEtaIEta;
685 // myphoton_sieip=CoviEtaiPhi;
686 // myphoton_etawidth=EtaWidth;
687 // myphoton_phiwidth=PhiWidth;
688 // myphoton_r9=R9;
689 // myphoton_s4ratio=p->S4Ratio();
690 // myphoton_SCeta=ScEta_MVA;
691 // event_rho= _tRho;
692
693 // myphoton_ESEffSigmaRR=-99;
694
695 // if(!isbarrel){
696 // myphoton_ESEffSigmaRR=p->EffSigmaRR();
697 // }
698
699 // if (isbarrel) {
700 // reader = fReaderBarrel;
701 // }
702 // else {
703 // reader = fReaderEndcap;
704 // }
705
706 // assert(reader);
707
708 // double bdt = reader->EvaluateMVA("BDT method");
709
710 // /* printf("HoE: %f\n",HoE);
711 // printf("covIEtaIEta: %f\n",covIEtaIEta);
712 // printf("tIso1abs: %f\n",tIso1abs);
713 // printf("tIso3abs: %f\n",tIso3abs);
714 // printf("tIso2abs: %f\n",tIso2abs);
715
716 // printf("absIsoEcal: %f\n",absIsoEcal);
717 // printf("absIsoHcal: %f\n",absIsoHcal);
718 // printf("RelEMax: %f\n",RelEMax);
719 // printf("RelETop: %f\n",RelETop);
720 // printf("RelEBottom: %f\n",RelEBottom);
721 // printf("RelELeft: %f\n",RelELeft);
722 // printf("RelERight: %f\n",RelERight);
723 // printf("RelE2x5Max: %f\n",RelE2x5Max);
724 // printf("RelE2x5Top: %f\n",RelE2x5Top);
725 // printf("RelE2x5Bottom: %f\n",RelE2x5Bottom);
726 // printf("RelE2x5Left: %f\n",RelE2x5Left);
727 // printf("RelE2x5Right;: %f\n",RelE2x5Right);
728 // printf("RelE5x5: %f\n",RelE5x5);
729
730 // printf("EtaWidth: %f\n",EtaWidth);
731 // printf("PhiWidth: %f\n",PhiWidth);
732 // printf("CoviEtaiPhi: %f\n",CoviEtaiPhi);
733 // printf("CoviPhiiPhi: %f\n",CoviPhiiPhi);
734
735 // if (!isbarrel) {
736 // printf("RelPreshowerEnergy: %f\n",RelPreshowerEnergy);
737 // }*/
738
739 // return bdt;
740 // }
741
742 // Float_t MVATools::GetMVAbdtValue_2011(const Photon* p,const Vertex* vtx,const TrackCol* trackCol,const VertexCol* vtxCol,Double_t _tRho,const ElectronCol* els,Bool_t applyElectronVeto) {
743
744 // //get the variables used to compute MVA variables
745 // ecalIso3 = p->EcalRecHitIsoDr03();
746 // ecalIso4 = p->EcalRecHitIsoDr04();
747 // hcalIso4 = p->HcalTowerSumEtDr04();
748
749 // wVtxInd = 0;
750
751 // trackIso1 = IsolationTools::CiCTrackIsolation(p,vtx, 0.3, 0.02, 0.0, 0.0, 0.1, 1.0, trackCol, NULL, NULL, (!applyElectronVeto ? els : NULL) );//Question Ming:whyfPV->At(0) instead of selected vertex using ranking method?
752
753 // // track iso worst vtx
754 // trackIso2 = IsolationTools::CiCTrackIsolation(p,vtx, 0.4, 0.02, 0.0, 0.0, 0.1, 1.0, trackCol, &wVtxInd,vtxCol, (!applyElectronVeto ? els : NULL) );
755
756 // combIso1 = ecalIso3+hcalIso4+trackIso1 - 0.17*_tRho;
757 // combIso2 = ecalIso4+hcalIso4+trackIso2 - 0.52*_tRho;
758
759 // RawEnergy = p->SCluster()->RawEnergy();
760
761 // ScEta = p->SCluster()->Eta();
762
763 // //mva varialbes v1 and v2
764 // tIso1 = (combIso1) *50./p->Et();
765 // tIso3 = (trackIso1)*50./p->Et();
766 // tIso2 = (combIso2) *50./(p->MomVtx(vtxCol->At(wVtxInd)->Position()).Pt());
767 // RelIsoEcal=(ecalIso3-0.17*_tRho)/p->Et();
768 // RelIsoHcal=(hcalIso4-0.17*_tRho)/p->Et();
769
770 // //compute mva variables for v3
771 // HoE = p->HadOverEm();
772 // covIEtaIEta = p->CoviEtaiEta();
773 // tIso1abs = combIso1;
774 // tIso3abs = trackIso1;
775 // tIso2abs = combIso2;
776 // R9 = p->R9();
777
778 // absIsoEcal=(ecalIso3-0.17*_tRho);
779 // absIsoHcal=(hcalIso4-0.17*_tRho);
780 // RelEMax=p->SCluster()->Seed()->EMax()/RawEnergy;
781 // RelETop=p->SCluster()->Seed()->ETop()/RawEnergy;
782 // RelEBottom=p->SCluster()->Seed()->EBottom()/RawEnergy;
783 // RelELeft=p->SCluster()->Seed()->ELeft()/RawEnergy;
784 // RelERight=p->SCluster()->Seed()->ERight()/RawEnergy;
785 // RelE2x5Max=p->SCluster()->Seed()->E2x5Max()/RawEnergy;
786 // RelE2x5Top=p->SCluster()->Seed()->E2x5Top()/RawEnergy;
787 // RelE2x5Bottom=p->SCluster()->Seed()->E2x5Bottom()/RawEnergy;
788 // RelE2x5Left=p->SCluster()->Seed()->E2x5Left()/RawEnergy;
789 // RelE2x5Right=p->SCluster()->Seed()->E2x5Right()/RawEnergy;
790 // RelE5x5=p->SCluster()->Seed()->E5x5()/RawEnergy;
791
792 // EtaWidth=p->EtaWidth();
793 // PhiWidth=p->PhiWidth();
794 // CoviEtaiPhi=p->SCluster()->Seed()->CoviEtaiPhi();
795 // CoviPhiiPhi=p->SCluster()->Seed()->CoviPhiiPhi();
796
797 // RelPreshowerEnergy=p->SCluster()->PreshowerEnergy()/RawEnergy;
798 // NVertexes=vtxCol->GetEntries();
799
800 // //spectator variables
801 // Pt_MVA=p->Pt();
802 // ScEta_MVA=p->SCluster()->Eta();
803
804 // //
805
806 // isbarrel = (fabs(ScEta_MVA)<1.4442);
807
808 // if (isbarrel) {
809 // reader = fReaderBarrel;
810 // }
811 // else {
812 // reader = fReaderEndcap;
813 // }
814
815 // assert(reader);
816
817 // double bdt = reader->EvaluateMVA("BDT method");
818
819 // /* printf("HoE: %f\n",HoE);
820 // printf("covIEtaIEta: %f\n",covIEtaIEta);
821 // printf("tIso1abs: %f\n",tIso1abs);
822 // printf("tIso3abs: %f\n",tIso3abs);
823 // printf("tIso2abs: %f\n",tIso2abs);
824
825 // printf("absIsoEcal: %f\n",absIsoEcal);
826 // printf("absIsoHcal: %f\n",absIsoHcal);
827 // printf("RelEMax: %f\n",RelEMax);
828 // printf("RelETop: %f\n",RelETop);
829 // printf("RelEBottom: %f\n",RelEBottom);
830 // printf("RelELeft: %f\n",RelELeft);
831 // printf("RelERight: %f\n",RelERight);
832 // printf("RelE2x5Max: %f\n",RelE2x5Max);
833 // printf("RelE2x5Top: %f\n",RelE2x5Top);
834 // printf("RelE2x5Bottom: %f\n",RelE2x5Bottom);
835 // printf("RelE2x5Left: %f\n",RelE2x5Left);
836 // printf("RelE2x5Right;: %f\n",RelE2x5Right);
837 // printf("RelE5x5: %f\n",RelE5x5);
838
839 // printf("EtaWidth: %f\n",EtaWidth);
840 // printf("PhiWidth: %f\n",PhiWidth);
841 // printf("CoviEtaiPhi: %f\n",CoviEtaiPhi);
842 // printf("CoviPhiiPhi: %f\n",CoviPhiiPhi);
843
844 // if (!isbarrel) {
845 // printf("RelPreshowerEnergy: %f\n",RelPreshowerEnergy);
846 // }*/
847
848 // return bdt;
849 // }