ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Utils/src/MVATools.cc
(Generate patch)

Comparing UserCode/MitPhysics/Utils/src/MVATools.cc (file contents):
Revision 1.8 by bendavid, Tue Dec 13 21:13:23 2011 UTC vs.
Revision 1.14 by mingyang, Sun Jun 10 16:28:40 2012 UTC

# Line 4 | Line 4
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 "TMVA/Tools.h"//MVA
13   #include "TMVA/Reader.h"//MVA
14  
15 +
16   ClassImp(mithep::MVATools)
17  
18   using namespace mithep;
# Line 55 | Line 58 | MVATools::MVATools():
58    RelIsoHcal(0),
59    tIso1(0),
60    tIso3(0),
61 <  tIso2(0)
61 >  tIso2(0),
62 >  ScEta(0.)
63   {
64    // Constructor.
65   }
# Line 157 | Line 161 | void MVATools::InitializeMVA(int Variabl
161        readers[i]->AddVariable( "RelPreshowerEnergy", &RelPreshowerEnergy );
162        }
163      }
164 +    
165 +    if(VariableType==7){
166 +      readers[i]->AddVariable( "HoE", &HoE );
167 +      readers[i]->AddVariable( "covIEtaIEta", &covIEtaIEta );
168 +      readers[i]->AddVariable( "tIso1abs", &tIso1abs );
169 +      readers[i]->AddVariable( "tIso3abs", &tIso3abs );
170 +      readers[i]->AddVariable( "tIso2abs", &tIso2abs );
171 +      readers[i]->AddVariable( "R9", &R9 );
172 +      readers[i]->AddVariable( "absIsoEcal", &absIsoEcal );
173 +      readers[i]->AddVariable( "absIsoHcal", &absIsoHcal );
174 +      readers[i]->AddVariable( "NVertexes", &NVertexes );
175 +      readers[i]->AddVariable( "ScEta", &ScEta );
176 +    }    
177 +
178 +    if(VariableType==10){
179 +      readers[i]->AddVariable( "HoE", &HoE );
180 +      readers[i]->AddVariable( "covIEtaIEta", &covIEtaIEta );
181 +      readers[i]->AddVariable( "tIso1abs", &tIso1abs );
182 +      readers[i]->AddVariable( "tIso3abs", &tIso3abs );
183 +      readers[i]->AddVariable( "tIso2abs", &tIso2abs );
184 +      readers[i]->AddVariable( "R9", &R9 );
185 +      readers[i]->AddVariable( "absIsoEcal", &absIsoEcal );
186 +      readers[i]->AddVariable( "absIsoHcal", &absIsoHcal );
187 +      readers[i]->AddVariable( "NVertexes", &NVertexes );
188 +      readers[i]->AddVariable( "ScEta", &ScEta );
189 +      readers[i]->AddVariable( "EtaWidth", &EtaWidth );
190 +      readers[i]->AddVariable( "PhiWidth", &PhiWidth );      
191 +    }    
192  
193 +    if(VariableType==1201){
194 +      readers[i]->AddVariable( "myphoton_pfchargedisogood03", &myphoton_pfchargedisogood03);
195 +      readers[i]->AddVariable( "myphoton_pfchargedisobad03", &myphoton_pfchargedisobad03);
196 +      readers[i]->AddVariable( "myphoton_pfphotoniso03", &myphoton_pfphotoniso03 );
197 +      readers[i]->AddVariable( "myphoton_sieie", &myphoton_sieie );
198 +      readers[i]->AddVariable( "myphoton_sieip", &myphoton_sieip );
199 +      readers[i]->AddVariable( "myphoton_etawidth", &myphoton_etawidth );
200 +      readers[i]->AddVariable( "myphoton_phiwidth", &myphoton_phiwidth );
201 +      readers[i]->AddVariable( "myphoton_r9", &myphoton_r9 );
202 +      readers[i]->AddVariable( "myphoton_s4ratio", &myphoton_s4ratio );
203 +      readers[i]->AddVariable( "myphoton_SCeta", &myphoton_SCeta );
204 +      readers[i]->AddVariable( "event_rho", &event_rho );
205 +      if(i==0){
206 +        readers[i]->AddVariable( "myphoton_ESEffSigmaRR", &myphoton_ESEffSigmaRR);
207 +      }
208 +    }
209 +    
210    }
211    
212    fReaderEndcap->BookMVA("BDT method",EndcapWeights);
# Line 173 | Line 222 | Bool_t MVATools::PassMVASelection(const
222    //initilize the bool value
223    PassMVA=kFALSE;
224    
225 <  Float_t photon_bdt =  MVATools::GetMVAbdtValue(p,vtx,trackCol,vtxCol, _tRho, els, applyElectronVeto);
225 >  Float_t photon_bdt =  MVATools::GetMVAbdtValue_2011(p,vtx,trackCol,vtxCol, _tRho, els, applyElectronVeto);
226    
227    if (isbarrel) {
228      if(bdt>bdtCutBarrel){
# Line 211 | Line 260 | Int_t MVATools::PassElectronVetoInt(cons
260    
261    isbarrel = (fabs(ScEta_MVA)<1.4442);
262  
263 <  //R9 = p->R9();
264 <  R9 = p->E33()/p->SCluster()->RawEnergy();
263 >  R9 = p->R9();
264 >  //R9 = p->E33()/p->SCluster()->RawEnergy();
265    
266    // check which category it is ...
267    _tCat = 1;
# Line 230 | Line 279 | Int_t MVATools::PassElectronVetoInt(cons
279  
280   //--------------------------------------------------------------------------------------------------
281  
282 < Float_t MVATools::GetMVAbdtValue(const Photon* p,const Vertex* vtx,const TrackCol* trackCol,const VertexCol* vtxCol,Double_t _tRho, const ElectronCol* els, Bool_t applyElectronVeto) {
282 > 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) {
283    
284    //get the variables used to compute MVA variables
285    ecalIso3 = p->EcalRecHitIsoDr03();
# Line 249 | Line 298 | Float_t MVATools::GetMVAbdtValue(const P
298    
299    RawEnergy = p->SCluster()->RawEnergy();
300    
301 +  ScEta = p->SCluster()->Eta();
302 +  
303    //mva varialbes v1 and v2
304    tIso1 = (combIso1) *50./p->Et();
305    tIso3 = (trackIso1)*50./p->Et();
# Line 278 | Line 329 | Float_t MVATools::GetMVAbdtValue(const P
329    RelE2x5Right=p->SCluster()->Seed()->E2x5Right()/RawEnergy;
330    RelE5x5=p->SCluster()->Seed()->E5x5()/RawEnergy;
331    
332 <  EtaWidth=p->SCluster()->EtaWidth();
333 <  PhiWidth=p->SCluster()->PhiWidth();
332 >  EtaWidth=p->EtaWidth();
333 >  PhiWidth=p->PhiWidth();
334    CoviEtaiPhi=p->SCluster()->Seed()->CoviEtaiPhi();
335    CoviPhiiPhi=p->SCluster()->Seed()->CoviPhiiPhi();
336  
# Line 289 | Line 340 | Float_t MVATools::GetMVAbdtValue(const P
340    //spectator variables
341    Pt_MVA=p->Pt();
342    ScEta_MVA=p->SCluster()->Eta();
343 +
344 +  //
345 +
346 +  isbarrel = (fabs(ScEta_MVA)<1.4442);
347 +  
348 +  //variable 1201
349 +  myphoton_pfchargedisogood03=IsolationTools::PFChargedIsolation(p,vtx,0.3,0,fPFCands);
350 +  myphoton_pfchargedisobad03=IsolationTools::PFChargedIsolation(p,vtx,0.3,0,fPFCands,&wVtxInd,vtxCol);
351 +  myphoton_pfphotoniso03=IsolationTools::PFGammaIsolation(p,0.3,0,fPFCands);
352 +  myphoton_sieie=covIEtaIEta;
353 +  myphoton_sieip=CoviEtaiPhi;
354 +  myphoton_etawidth=EtaWidth;
355 +  myphoton_phiwidth=PhiWidth;
356 +  myphoton_r9=R9;
357 +  myphoton_s4ratio=p->SCluster()->Seed()->E2x2()/p->SCluster()->Seed()->E5x5();
358 +  myphoton_SCeta=ScEta_MVA;
359 +  event_rho= _tRho;
360 +
361 +  myphoton_ESEffSigmaRR=-99;
362 +
363 +  if(!isbarrel){
364 +    myphoton_ESEffSigmaRR=float(sqrt((p->SCluster()->PsEffWidthSigmaXX())*(p->SCluster()->PsEffWidthSigmaXX())+(p->SCluster()->PsEffWidthSigmaYY())*(p->SCluster()->PsEffWidthSigmaYY())));
365 +  }
366 +  
367 +  if (isbarrel) {
368 +    reader = fReaderBarrel;
369 +  }
370 +  else {
371 +    reader = fReaderEndcap;
372 +  }
373 +  
374 +  assert(reader);
375 +
376 +  bdt = reader->EvaluateMVA("BDT method");
377 +
378 +  /* printf("HoE: %f\n",HoE);
379 +  printf("covIEtaIEta: %f\n",covIEtaIEta);
380 +  printf("tIso1abs: %f\n",tIso1abs);
381 +  printf("tIso3abs: %f\n",tIso3abs);
382 +  printf("tIso2abs: %f\n",tIso2abs);
383 +  
384 +  printf("absIsoEcal: %f\n",absIsoEcal);
385 +  printf("absIsoHcal: %f\n",absIsoHcal);
386 +  printf("RelEMax: %f\n",RelEMax);
387 +  printf("RelETop: %f\n",RelETop);
388 +  printf("RelEBottom: %f\n",RelEBottom);
389 +  printf("RelELeft: %f\n",RelELeft);
390 +  printf("RelERight: %f\n",RelERight);
391 +  printf("RelE2x5Max: %f\n",RelE2x5Max);
392 +  printf("RelE2x5Top: %f\n",RelE2x5Top);
393 +  printf("RelE2x5Bottom: %f\n",RelE2x5Bottom);
394 +  printf("RelE2x5Left: %f\n",RelE2x5Left);
395 +  printf("RelE2x5Right;: %f\n",RelE2x5Right);
396 +  printf("RelE5x5: %f\n",RelE5x5);
397 +  
398 +  printf("EtaWidth: %f\n",EtaWidth);
399 +  printf("PhiWidth: %f\n",PhiWidth);
400 +  printf("CoviEtaiPhi: %f\n",CoviEtaiPhi);
401 +  printf("CoviPhiiPhi: %f\n",CoviPhiiPhi);
402 +  
403 +  if (!isbarrel) {
404 +    printf("RelPreshowerEnergy: %f\n",RelPreshowerEnergy);
405 +    }*/
406 +  
407 +  return bdt;
408 + }
409 +
410 + 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) {
411 +  
412 +  //get the variables used to compute MVA variables
413 +  ecalIso3 = p->EcalRecHitIsoDr03();
414 +  ecalIso4 = p->EcalRecHitIsoDr04();
415 +  hcalIso4 = p->HcalTowerSumEtDr04();
416 +  
417 +  wVtxInd = 0;
418    
419 +  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?
420 +    
421 +  // track iso worst vtx
422 +  trackIso2 = IsolationTools::CiCTrackIsolation(p,vtx, 0.4, 0.02, 0.0, 0.0, 0.1, 1.0, trackCol, &wVtxInd,vtxCol, (!applyElectronVeto ? els : NULL) );
423 +  
424 +  combIso1 = ecalIso3+hcalIso4+trackIso1 - 0.17*_tRho;
425 +  combIso2 = ecalIso4+hcalIso4+trackIso2 - 0.52*_tRho;
426 +  
427 +  RawEnergy = p->SCluster()->RawEnergy();
428 +  
429 +  ScEta = p->SCluster()->Eta();
430 +  
431 +  //mva varialbes v1 and v2
432 +  tIso1 = (combIso1) *50./p->Et();
433 +  tIso3 = (trackIso1)*50./p->Et();
434 +  tIso2 = (combIso2) *50./(p->MomVtx(vtxCol->At(wVtxInd)->Position()).Pt());
435 +  RelIsoEcal=(ecalIso3-0.17*_tRho)/p->Et();
436 +  RelIsoHcal=(hcalIso4-0.17*_tRho)/p->Et();
437 +
438 +  //compute mva variables for v3
439 +  HoE = p->HadOverEm();
440 +  covIEtaIEta = p->CoviEtaiEta();
441 +  tIso1abs = combIso1;
442 +  tIso3abs = trackIso1;
443 +  tIso2abs = combIso2;
444 +  R9 = p->R9();
445 +
446 +  absIsoEcal=(ecalIso3-0.17*_tRho);
447 +  absIsoHcal=(hcalIso4-0.17*_tRho);
448 +  RelEMax=p->SCluster()->Seed()->EMax()/RawEnergy;
449 +  RelETop=p->SCluster()->Seed()->ETop()/RawEnergy;
450 +  RelEBottom=p->SCluster()->Seed()->EBottom()/RawEnergy;
451 +  RelELeft=p->SCluster()->Seed()->ELeft()/RawEnergy;
452 +  RelERight=p->SCluster()->Seed()->ERight()/RawEnergy;
453 +  RelE2x5Max=p->SCluster()->Seed()->E2x5Max()/RawEnergy;
454 +  RelE2x5Top=p->SCluster()->Seed()->E2x5Top()/RawEnergy;
455 +  RelE2x5Bottom=p->SCluster()->Seed()->E2x5Bottom()/RawEnergy;
456 +  RelE2x5Left=p->SCluster()->Seed()->E2x5Left()/RawEnergy;
457 +  RelE2x5Right=p->SCluster()->Seed()->E2x5Right()/RawEnergy;
458 +  RelE5x5=p->SCluster()->Seed()->E5x5()/RawEnergy;
459 +  
460 +  EtaWidth=p->EtaWidth();
461 +  PhiWidth=p->PhiWidth();
462 +  CoviEtaiPhi=p->SCluster()->Seed()->CoviEtaiPhi();
463 +  CoviPhiiPhi=p->SCluster()->Seed()->CoviPhiiPhi();
464 +
465 +  RelPreshowerEnergy=p->SCluster()->PreshowerEnergy()/RawEnergy;
466 +  NVertexes=vtxCol->GetEntries();
467 +  
468 +  //spectator variables
469 +  Pt_MVA=p->Pt();
470 +  ScEta_MVA=p->SCluster()->Eta();
471 +
472 +  //
473 +
474    isbarrel = (fabs(ScEta_MVA)<1.4442);
475    
476    if (isbarrel) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines