CMS 3D CMS Logo

Public Member Functions | Private Attributes

AntiElectronIDMVA Class Reference

#include <AntiElectronIDMVA.h>

List of all members.

Public Member Functions

 AntiElectronIDMVA ()
void Initialize (std::string methodName, std::string oneProng0Pi0_BL, std::string oneProng1pi0wGSF_BL, std::string oneProng1pi0woGSF_BL, std::string oneProng0Pi0_EC, std::string oneProng1pi0wGSF_EC, std::string oneProng1pi0woGSF_EC)
double MVAValue (Float_t TauEta, Float_t TauPt, Float_t TauSignalPFChargedCands, Float_t TauSignalPFGammaCands, Float_t TauLeadPFChargedHadrMva, Float_t TauLeadPFChargedHadrHoP, Float_t TauLeadPFChargedHadrEoP, Float_t TauHasGsf, Float_t TauVisMass, Float_t TauEmFraction, Float_t GammaEtaMom, Float_t GammaPhiMom, Float_t GammaEnFrac)
double MVAValue (Float_t TauEta, Float_t TauPt, Float_t TauSignalPFChargedCands, Float_t TauSignalPFGammaCands, Float_t TauLeadPFChargedHadrMva, Float_t TauLeadPFChargedHadrHoP, Float_t TauLeadPFChargedHadrEoP, Float_t TauHasGsf, Float_t TauVisMass, Float_t TauEmFraction, std::vector< Float_t > *GammasdEta, std::vector< Float_t > *GammasdPhi, std::vector< Float_t > *GammasPt)
double MVAValue (const reco::PFTauRef &thePFTauRef)
 ~AntiElectronIDMVA ()

Private Attributes

TMVA::Reader * fTMVAReader_ [6]
Float_t GammadEta_
Float_t GammadPhi_
Float_t GammadPt_
Bool_t isInitialized_
std::string methodName_
Float_t TauEmFraction_
Float_t TauLeadPFChargedHadrEoP_
Float_t TauLeadPFChargedHadrHoP_
Float_t TauLeadPFChargedHadrMva_
Float_t TauSignalPFGammaCands_
Float_t TauVisMass_

Detailed Description

Definition at line 33 of file AntiElectronIDMVA.h.


Constructor & Destructor Documentation

AntiElectronIDMVA::AntiElectronIDMVA ( )

Definition at line 5 of file AntiElectronIDMVA.cc.

References fTMVAReader_, and i.

                                    :
  isInitialized_(kFALSE),
  methodName_("BDT")
{
  for(UInt_t i=0; i<6; ++i) {
    fTMVAReader_[i] = 0;
  }
}
AntiElectronIDMVA::~AntiElectronIDMVA ( )

Definition at line 15 of file AntiElectronIDMVA.cc.

References fTMVAReader_, and i.

{
  for(UInt_t i=0; i<6; ++i) {
    if (fTMVAReader_[i]) delete fTMVAReader_[i];
  }
}

Member Function Documentation

void AntiElectronIDMVA::Initialize ( std::string  methodName,
std::string  oneProng0Pi0_BL,
std::string  oneProng1pi0wGSF_BL,
std::string  oneProng1pi0woGSF_BL,
std::string  oneProng0Pi0_EC,
std::string  oneProng1pi0wGSF_EC,
std::string  oneProng1pi0woGSF_EC 
)

Definition at line 23 of file AntiElectronIDMVA.cc.

References fTMVAReader_, GammadEta_, GammadPhi_, GammadPt_, i, isInitialized_, methodName_, TauLeadPFChargedHadrEoP_, TauLeadPFChargedHadrHoP_, TauLeadPFChargedHadrMva_, and TauVisMass_.

                                    {

  for(UInt_t i=0; i<6; ++i) {
    if (fTMVAReader_[i]) delete fTMVAReader_[i];
  }

  isInitialized_ = kTRUE;
  methodName_    = methodName;

  //TMVA::Tools::Instance();

  TMVA::Reader *readerX0BL = new TMVA::Reader( "!Color:!Silent:Error" );  
  readerX0BL->AddVariable("HoP",       &TauLeadPFChargedHadrHoP_);
  readerX0BL->AddVariable("EoP",       &TauLeadPFChargedHadrEoP_);
  //readerX0BL->AddVariable("emFraction",&TauEmFraction_);
  readerX0BL->SetVerbose(kTRUE);
  readerX0BL->BookMVA( methodName_, oneProng0Pi0_BL );

  TMVA::Reader *reader11BL = new TMVA::Reader( "!Color:!Silent:Error" );   
  reader11BL->AddVariable("mva",               &TauLeadPFChargedHadrMva_);
  reader11BL->AddVariable("visMass",           &TauVisMass_);
  reader11BL->AddVariable("etaMom2*TMath::Sqrt(gammaFrac)*pt", &GammadEta_);
  reader11BL->AddVariable("phiMom2*TMath::Sqrt(gammaFrac)*pt", &GammadPhi_);
  reader11BL->AddVariable("gammaFrac",         &GammadPt_);
  reader11BL->SetVerbose(kTRUE);
  reader11BL->BookMVA( methodName_, oneProng1pi0wGSF_BL );

  TMVA::Reader *reader01BL = new TMVA::Reader( "!Color:!Silent:Error" );   
  reader01BL->AddVariable("visMass",           &TauVisMass_);
  reader01BL->AddVariable("etaMom2*TMath::Sqrt(gammaFrac)*pt", &GammadEta_);
  reader01BL->AddVariable("phiMom2*TMath::Sqrt(gammaFrac)*pt", &GammadPhi_);
  reader01BL->AddVariable("gammaFrac",         &GammadPt_);
  reader01BL->SetVerbose(kTRUE);
  reader01BL->BookMVA( methodName_, oneProng1pi0woGSF_BL ); 


  TMVA::Reader *readerX0EC = new TMVA::Reader( "!Color:!Silent:Error" );
  readerX0EC->AddVariable("HoP",       &TauLeadPFChargedHadrHoP_);
  readerX0EC->AddVariable("EoP",       &TauLeadPFChargedHadrEoP_);
  //readerX0EC->AddVariable("emFraction",&TauEmFraction_);
  readerX0EC->SetVerbose(kTRUE);
  readerX0EC->BookMVA( methodName_, oneProng0Pi0_EC );

  TMVA::Reader *reader11EC = new TMVA::Reader( "!Color:!Silent:Error" );
  reader11EC->AddVariable("mva",               &TauLeadPFChargedHadrMva_);
  reader11EC->AddVariable("visMass",           &TauVisMass_);
  reader11EC->AddVariable("etaMom2*TMath::Sqrt(gammaFrac)*pt", &GammadEta_);
  reader11EC->AddVariable("phiMom2*TMath::Sqrt(gammaFrac)*pt", &GammadPhi_);
  reader11EC->AddVariable("gammaFrac",         &GammadPt_);
  reader11EC->SetVerbose(kTRUE);
  reader11EC->BookMVA( methodName_, oneProng1pi0wGSF_EC );

  TMVA::Reader *reader01EC = new TMVA::Reader( "!Color:!Silent:Error" );
  reader01EC->AddVariable("visMass",           &TauVisMass_);
  reader01EC->AddVariable("etaMom2*TMath::Sqrt(gammaFrac)*pt", &GammadEta_);
  reader01EC->AddVariable("phiMom2*TMath::Sqrt(gammaFrac)*pt", &GammadPhi_);
  reader01EC->AddVariable("gammaFrac",         &GammadPt_);
  reader01EC->SetVerbose(kTRUE);
  reader01EC->BookMVA( methodName_, oneProng1pi0woGSF_EC );


  fTMVAReader_[0] = readerX0BL;
  fTMVAReader_[1] = reader11BL;
  fTMVAReader_[2] = reader01BL;
  fTMVAReader_[3] = readerX0EC;
  fTMVAReader_[4] = reader11EC;
  fTMVAReader_[5] = reader01EC;


}
double AntiElectronIDMVA::MVAValue ( const reco::PFTauRef thePFTauRef)

Definition at line 245 of file AntiElectronIDMVA.cc.

References asciidump::at, gather_cfg::cout, dPhi(), fTMVAReader_, GammadEta_, GammadPhi_, GammadPt_, isInitialized_, gen::k, siStripFEDMonitor_P5_cff::Max, methodName_, Pi, findQualityFiles::size, TauEmFraction_, TauLeadPFChargedHadrEoP_, TauLeadPFChargedHadrHoP_, TauLeadPFChargedHadrMva_, and TauVisMass_.

                                                                 {

  if (!isInitialized_) { 
    std::cout << "Error: AntiElectronMVA with method 3 not properly initialized.\n"; 
    return -999;
  }
  
  double mva;

  TauVisMass_              = (*thePFTauRef).mass(); 
  TauLeadPFChargedHadrMva_ = TMath::Max((*thePFTauRef).electronPreIDOutput(),float(-1.0));
  TauLeadPFChargedHadrHoP_ = ((*thePFTauRef).leadPFChargedHadrCand())->hcalEnergy()/(*thePFTauRef).leadPFChargedHadrCand()->p();
  TauLeadPFChargedHadrEoP_ = ((*thePFTauRef).leadPFChargedHadrCand())->ecalEnergy()/(*thePFTauRef).leadPFChargedHadrCand()->p();
  TauEmFraction_           = TMath::Max((*thePFTauRef).emFraction(),float(0.0));

  std::vector<float> GammasdEta;
  std::vector<float> GammasdPhi;
  std::vector<float> GammasPt;

  for(unsigned int k = 0 ; k < ((*thePFTauRef).signalPFGammaCands()).size() ; k++){
    reco::PFCandidateRef gamma = ((*thePFTauRef).signalPFGammaCands()).at(k);
    if( ((*thePFTauRef).leadPFChargedHadrCand()).isNonnull() ){
      GammasdEta.push_back( gamma->eta() - (*thePFTauRef).leadPFChargedHadrCand()->eta() );
      GammasdPhi.push_back( gamma->phi() - (*thePFTauRef).leadPFChargedHadrCand()->phi() );
    }
    else{
      GammasdEta.push_back( gamma->eta() - (*thePFTauRef).eta() );
      GammasdPhi.push_back( gamma->phi() - (*thePFTauRef).phi() );
    }
    GammasPt.push_back(  gamma->pt() );
  }

  float sumPt  = 0;
  float dEta   = 0;
  float dEta2  = 0;
  float dPhi   = 0;
  float dPhi2  = 0;
  float sumPt2 = 0;

  for(unsigned int k = 0 ; k < GammasPt.size() ; k++){
    float pt_k  = GammasPt[k];
    float phi_k = GammasdPhi[k];
    if (GammasdPhi[k] > TMath::Pi()) phi_k = GammasdPhi[k] - 2*TMath::Pi();
    else if(GammasdPhi[k] < -TMath::Pi()) phi_k = GammasdPhi[k] + 2*TMath::Pi();
    float eta_k = GammasdEta[k];
    sumPt  +=  pt_k;
    sumPt2 += (pt_k*pt_k);
    dEta   += (pt_k*eta_k);
    dEta2  += (pt_k*eta_k*eta_k);
    dPhi   += (pt_k*phi_k);
    dPhi2  += (pt_k*phi_k*phi_k);  
  }

  GammadPt_ = sumPt/(*thePFTauRef).pt();

  if(sumPt>0){
    dEta  /= sumPt;
    dPhi  /= sumPt;
    dEta2 /= sumPt;
    dPhi2 /= sumPt;
  }

  //GammadEta_ = dEta;
  //GammadPhi_ = dPhi;
  
  GammadEta_ = TMath::Sqrt(dEta2)*TMath::Sqrt(GammadPt_)*(*thePFTauRef).pt();
  GammadPhi_ = TMath::Sqrt(dPhi2)*TMath::Sqrt(GammadPt_)*(*thePFTauRef).pt();

  if( ((*thePFTauRef).signalPFChargedHadrCands()).size() == 3) 
    mva = 1.0;
  else if( ((*thePFTauRef).signalPFChargedHadrCands()).size()==1 && ((*thePFTauRef).signalPFGammaCands()).size()==0){
    if(TMath::Abs((*thePFTauRef).eta())<1.5) 
      mva = fTMVAReader_[0]->EvaluateMVA( methodName_ );
    else  
      mva = fTMVAReader_[3]->EvaluateMVA( methodName_ );
  }
  else if( ((*thePFTauRef).signalPFChargedHadrCands()).size()==1 && ((*thePFTauRef).signalPFGammaCands()).size()>0 && (((*thePFTauRef).leadPFChargedHadrCand())->gsfTrackRef()).isNonnull()){
    if(TMath::Abs((*thePFTauRef).eta())<1.5) 
      mva = fTMVAReader_[1]->EvaluateMVA( methodName_ );
    else  
      mva = fTMVAReader_[4]->EvaluateMVA( methodName_ );
  }
  else if( ((*thePFTauRef).signalPFChargedHadrCands()).size()==1 && ((*thePFTauRef).signalPFGammaCands()).size()>0 && !(((*thePFTauRef).leadPFChargedHadrCand())->gsfTrackRef()).isNonnull()){
    if(TMath::Abs((*thePFTauRef).eta())<1.5) 
      mva = fTMVAReader_[2]->EvaluateMVA( methodName_ );
    else  
      mva = fTMVAReader_[5]->EvaluateMVA( methodName_ );
  }
  else{
    mva = -99;
  }

  return mva;

}
double AntiElectronIDMVA::MVAValue ( Float_t  TauEta,
Float_t  TauPt,
Float_t  TauSignalPFChargedCands,
Float_t  TauSignalPFGammaCands,
Float_t  TauLeadPFChargedHadrMva,
Float_t  TauLeadPFChargedHadrHoP,
Float_t  TauLeadPFChargedHadrEoP,
Float_t  TauHasGsf,
Float_t  TauVisMass,
Float_t  TauEmFraction,
Float_t  GammaEtaMom,
Float_t  GammaPhiMom,
Float_t  GammaEnFrac 
)

Definition at line 190 of file AntiElectronIDMVA.cc.

References gather_cfg::cout, fTMVAReader_, GammadEta_, GammadPhi_, GammadPt_, isInitialized_, siStripFEDMonitor_P5_cff::Max, methodName_, TauEmFraction_, TauLeadPFChargedHadrEoP_, TauLeadPFChargedHadrHoP_, TauLeadPFChargedHadrMva_, and TauVisMass_.

                                    {

  if (!isInitialized_) { 
    std::cout << "Error: AntiElectronMVA with method 2 not properly initialized.\n"; 
    return -999;
  }


  double mva;

  TauVisMass_              = TauVisMass; 
  TauLeadPFChargedHadrMva_ = TMath::Max(TauLeadPFChargedHadrMva,float(-1.0));
  TauLeadPFChargedHadrHoP_ = TauLeadPFChargedHadrHoP;
  TauLeadPFChargedHadrEoP_ = TauLeadPFChargedHadrEoP;
  TauEmFraction_           = TMath::Max(TauEmFraction,float(0.0));
  GammadPt_                = GammaEnFrac;
  GammadEta_               = GammaEtaMom;
  GammadPhi_               = GammaPhiMom;
  
  if( TauSignalPFChargedCands==3 ) 
    mva = 1.0;
  else if( TauSignalPFChargedCands==1 && TauSignalPFGammaCands==0){
    if(TMath::Abs(TauEta)<1.5) 
      mva = fTMVAReader_[0]->EvaluateMVA( methodName_ );
    else  
      mva = fTMVAReader_[3]->EvaluateMVA( methodName_ );
  }
  else if( TauSignalPFChargedCands==1 && TauSignalPFGammaCands>0 && TauHasGsf>0.5){
    if(TMath::Abs(TauEta)<1.5) 
      mva = fTMVAReader_[1]->EvaluateMVA( methodName_ );
    else  
      mva = fTMVAReader_[4]->EvaluateMVA( methodName_ );
  }
  else if( TauSignalPFChargedCands==1 && TauSignalPFGammaCands>0 && TauHasGsf<0.5){
    if(TMath::Abs(TauEta)<1.5) 
      mva = fTMVAReader_[2]->EvaluateMVA( methodName_ );
    else  
      mva = fTMVAReader_[5]->EvaluateMVA( methodName_ );
  }
  else{
    mva = -99.;
  }

  return mva;

}
double AntiElectronIDMVA::MVAValue ( Float_t  TauEta,
Float_t  TauPt,
Float_t  TauSignalPFChargedCands,
Float_t  TauSignalPFGammaCands,
Float_t  TauLeadPFChargedHadrMva,
Float_t  TauLeadPFChargedHadrHoP,
Float_t  TauLeadPFChargedHadrEoP,
Float_t  TauHasGsf,
Float_t  TauVisMass,
Float_t  TauEmFraction,
std::vector< Float_t > *  GammasdEta,
std::vector< Float_t > *  GammasdPhi,
std::vector< Float_t > *  GammasPt 
)

Definition at line 103 of file AntiElectronIDMVA.cc.

References gather_cfg::cout, dPhi(), fTMVAReader_, GammadEta_, GammadPhi_, GammadPt_, isInitialized_, gen::k, siStripFEDMonitor_P5_cff::Max, methodName_, Pi, TauEmFraction_, TauLeadPFChargedHadrEoP_, TauLeadPFChargedHadrHoP_, TauLeadPFChargedHadrMva_, and TauVisMass_.

                                    {

  if (!isInitialized_) { 
    std::cout << "Error: AntiElectronMVA with method 1 not properly initialized.\n"; 
    return -999;
  }

  double mva;

  TauVisMass_              = TauVisMass; 
  TauLeadPFChargedHadrMva_ = TMath::Max(TauLeadPFChargedHadrMva,float(-1.0));
  TauLeadPFChargedHadrHoP_ = TauLeadPFChargedHadrHoP;
  TauLeadPFChargedHadrEoP_ = TauLeadPFChargedHadrEoP;
  TauEmFraction_           = TMath::Max(TauEmFraction,float(0.0));

  float sumPt  = 0;
  float dEta   = 0;
  float dEta2  = 0;
  float dPhi   = 0;
  float dPhi2  = 0;
  float sumPt2 = 0;

  for(unsigned int k = 0 ; k < GammasPt->size() ; k++){
    float pt_k  = (*GammasPt)[k];
    float phi_k = (*GammasdPhi)[k];
    if ((*GammasdPhi)[k] > TMath::Pi()) phi_k = (*GammasdPhi)[k] - 2*TMath::Pi();
    else if((*GammasdPhi)[k] < -TMath::Pi()) phi_k = (*GammasdPhi)[k] + 2*TMath::Pi();
    float eta_k = (*GammasdEta)[k];
    sumPt  +=  pt_k;
    sumPt2 += (pt_k*pt_k);
    dEta   += (pt_k*eta_k);
    dEta2  += (pt_k*eta_k*eta_k);
    dPhi   += (pt_k*phi_k);
    dPhi2  += (pt_k*phi_k*phi_k);  
  }

  GammadPt_ = sumPt/TauPt;

  if(sumPt>0){
    dEta  /= sumPt;
    dPhi  /= sumPt;
    dEta2 /= sumPt;
    dPhi2 /= sumPt;

  }

  //GammadEta_ = dEta;
  //GammadPhi_ = dPhi;
  
  GammadEta_ = TMath::Sqrt(dEta2)*TMath::Sqrt(GammadPt_)*TauPt;
  GammadPhi_ = TMath::Sqrt(dPhi2)*TMath::Sqrt(GammadPt_)*TauPt;


  if( TauSignalPFChargedCands==3 ) 
    mva = 1.0;
  else if( TauSignalPFChargedCands==1 && TauSignalPFGammaCands==0){
    if(TMath::Abs(TauEta)<1.5) 
      mva = fTMVAReader_[0]->EvaluateMVA( methodName_ );
    else  
      mva = fTMVAReader_[3]->EvaluateMVA( methodName_ );
  }
  else if( TauSignalPFChargedCands==1 && TauSignalPFGammaCands>0 && TauHasGsf>0.5){
    if(TMath::Abs(TauEta)<1.5) 
      mva = fTMVAReader_[1]->EvaluateMVA( methodName_ );
    else  
      mva = fTMVAReader_[4]->EvaluateMVA( methodName_ );
  }
  else if( TauSignalPFChargedCands==1 && TauSignalPFGammaCands>0 && TauHasGsf<0.5){
    if(TMath::Abs(TauEta)<1.5) 
      mva = fTMVAReader_[2]->EvaluateMVA( methodName_ );
    else  
      mva = fTMVAReader_[5]->EvaluateMVA( methodName_ );
  }
  else{
    mva = -99;
  }

  return mva;

}

Member Data Documentation

TMVA::Reader* AntiElectronIDMVA::fTMVAReader_[6] [private]

Definition at line 107 of file AntiElectronIDMVA.h.

Referenced by AntiElectronIDMVA(), Initialize(), MVAValue(), and ~AntiElectronIDMVA().

Float_t AntiElectronIDMVA::GammadEta_ [private]

Definition at line 110 of file AntiElectronIDMVA.h.

Referenced by Initialize(), and MVAValue().

Float_t AntiElectronIDMVA::GammadPhi_ [private]

Definition at line 111 of file AntiElectronIDMVA.h.

Referenced by Initialize(), and MVAValue().

Float_t AntiElectronIDMVA::GammadPt_ [private]

Definition at line 112 of file AntiElectronIDMVA.h.

Referenced by Initialize(), and MVAValue().

Definition at line 105 of file AntiElectronIDMVA.h.

Referenced by Initialize(), and MVAValue().

std::string AntiElectronIDMVA::methodName_ [private]

Definition at line 106 of file AntiElectronIDMVA.h.

Referenced by Initialize(), and MVAValue().

Definition at line 116 of file AntiElectronIDMVA.h.

Referenced by MVAValue().

Definition at line 115 of file AntiElectronIDMVA.h.

Referenced by Initialize(), and MVAValue().

Definition at line 114 of file AntiElectronIDMVA.h.

Referenced by Initialize(), and MVAValue().

Definition at line 113 of file AntiElectronIDMVA.h.

Referenced by Initialize(), and MVAValue().

Definition at line 108 of file AntiElectronIDMVA.h.

Float_t AntiElectronIDMVA::TauVisMass_ [private]

Definition at line 109 of file AntiElectronIDMVA.h.

Referenced by Initialize(), and MVAValue().