00001 #include <TFile.h>
00002 #include <TMath.h>
00003 #include "RecoTauTag/RecoTau//interface/AntiElectronIDMVA.h"
00004
00005 AntiElectronIDMVA::AntiElectronIDMVA():
00006 isInitialized_(kFALSE),
00007 methodName_("BDT")
00008 {
00009 for(UInt_t i=0; i<6; ++i) {
00010 fTMVAReader_[i] = 0;
00011 }
00012 }
00013
00014
00015 AntiElectronIDMVA::~AntiElectronIDMVA()
00016 {
00017 for(UInt_t i=0; i<6; ++i) {
00018 if (fTMVAReader_[i]) delete fTMVAReader_[i];
00019 }
00020 }
00021
00022
00023 void AntiElectronIDMVA::Initialize(std::string methodName,
00024 std::string oneProng0Pi0_BL,
00025 std::string oneProng1pi0wGSF_BL,
00026 std::string oneProng1pi0woGSF_BL,
00027 std::string oneProng0Pi0_EC,
00028 std::string oneProng1pi0wGSF_EC,
00029 std::string oneProng1pi0woGSF_EC
00030 ){
00031
00032 for(UInt_t i=0; i<6; ++i) {
00033 if (fTMVAReader_[i]) delete fTMVAReader_[i];
00034 }
00035
00036 isInitialized_ = kTRUE;
00037 methodName_ = methodName;
00038
00039
00040
00041 TMVA::Reader *readerX0BL = new TMVA::Reader( "!Color:!Silent:Error" );
00042 readerX0BL->AddVariable("HoP", &TauLeadPFChargedHadrHoP_);
00043 readerX0BL->AddVariable("EoP", &TauLeadPFChargedHadrEoP_);
00044
00045 readerX0BL->SetVerbose(kTRUE);
00046 readerX0BL->BookMVA( methodName_, oneProng0Pi0_BL );
00047
00048 TMVA::Reader *reader11BL = new TMVA::Reader( "!Color:!Silent:Error" );
00049 reader11BL->AddVariable("mva", &TauLeadPFChargedHadrMva_);
00050 reader11BL->AddVariable("visMass", &TauVisMass_);
00051 reader11BL->AddVariable("etaMom2*TMath::Sqrt(gammaFrac)*pt", &GammadEta_);
00052 reader11BL->AddVariable("phiMom2*TMath::Sqrt(gammaFrac)*pt", &GammadPhi_);
00053 reader11BL->AddVariable("gammaFrac", &GammadPt_);
00054 reader11BL->SetVerbose(kTRUE);
00055 reader11BL->BookMVA( methodName_, oneProng1pi0wGSF_BL );
00056
00057 TMVA::Reader *reader01BL = new TMVA::Reader( "!Color:!Silent:Error" );
00058 reader01BL->AddVariable("visMass", &TauVisMass_);
00059 reader01BL->AddVariable("etaMom2*TMath::Sqrt(gammaFrac)*pt", &GammadEta_);
00060 reader01BL->AddVariable("phiMom2*TMath::Sqrt(gammaFrac)*pt", &GammadPhi_);
00061 reader01BL->AddVariable("gammaFrac", &GammadPt_);
00062 reader01BL->SetVerbose(kTRUE);
00063 reader01BL->BookMVA( methodName_, oneProng1pi0woGSF_BL );
00064
00066
00067 TMVA::Reader *readerX0EC = new TMVA::Reader( "!Color:!Silent:Error" );
00068 readerX0EC->AddVariable("HoP", &TauLeadPFChargedHadrHoP_);
00069 readerX0EC->AddVariable("EoP", &TauLeadPFChargedHadrEoP_);
00070
00071 readerX0EC->SetVerbose(kTRUE);
00072 readerX0EC->BookMVA( methodName_, oneProng0Pi0_EC );
00073
00074 TMVA::Reader *reader11EC = new TMVA::Reader( "!Color:!Silent:Error" );
00075 reader11EC->AddVariable("mva", &TauLeadPFChargedHadrMva_);
00076 reader11EC->AddVariable("visMass", &TauVisMass_);
00077 reader11EC->AddVariable("etaMom2*TMath::Sqrt(gammaFrac)*pt", &GammadEta_);
00078 reader11EC->AddVariable("phiMom2*TMath::Sqrt(gammaFrac)*pt", &GammadPhi_);
00079 reader11EC->AddVariable("gammaFrac", &GammadPt_);
00080 reader11EC->SetVerbose(kTRUE);
00081 reader11EC->BookMVA( methodName_, oneProng1pi0wGSF_EC );
00082
00083 TMVA::Reader *reader01EC = new TMVA::Reader( "!Color:!Silent:Error" );
00084 reader01EC->AddVariable("visMass", &TauVisMass_);
00085 reader01EC->AddVariable("etaMom2*TMath::Sqrt(gammaFrac)*pt", &GammadEta_);
00086 reader01EC->AddVariable("phiMom2*TMath::Sqrt(gammaFrac)*pt", &GammadPhi_);
00087 reader01EC->AddVariable("gammaFrac", &GammadPt_);
00088 reader01EC->SetVerbose(kTRUE);
00089 reader01EC->BookMVA( methodName_, oneProng1pi0woGSF_EC );
00090
00091
00092 fTMVAReader_[0] = readerX0BL;
00093 fTMVAReader_[1] = reader11BL;
00094 fTMVAReader_[2] = reader01BL;
00095 fTMVAReader_[3] = readerX0EC;
00096 fTMVAReader_[4] = reader11EC;
00097 fTMVAReader_[5] = reader01EC;
00098
00099
00100 }
00101
00102
00103 double AntiElectronIDMVA::MVAValue(Float_t TauEta, Float_t TauPt,
00104 Float_t TauSignalPFChargedCands, Float_t TauSignalPFGammaCands,
00105 Float_t TauLeadPFChargedHadrMva,
00106 Float_t TauLeadPFChargedHadrHoP, Float_t TauLeadPFChargedHadrEoP,
00107 Float_t TauHasGsf, Float_t TauVisMass, Float_t TauEmFraction,
00108 std::vector<Float_t>* GammasdEta, std::vector<Float_t>* GammasdPhi, std::vector<Float_t>* GammasPt
00109 ){
00110
00111 if (!isInitialized_) {
00112 std::cout << "Error: AntiElectronMVA with method 1 not properly initialized.\n";
00113 return -999;
00114 }
00115
00116 double mva;
00117
00118 TauVisMass_ = TauVisMass;
00119 TauLeadPFChargedHadrMva_ = TMath::Max(TauLeadPFChargedHadrMva,float(-1.0));
00120 TauLeadPFChargedHadrHoP_ = TauLeadPFChargedHadrHoP;
00121 TauLeadPFChargedHadrEoP_ = TauLeadPFChargedHadrEoP;
00122 TauEmFraction_ = TMath::Max(TauEmFraction,float(0.0));
00123
00124 float sumPt = 0;
00125 float dEta = 0;
00126 float dEta2 = 0;
00127 float dPhi = 0;
00128 float dPhi2 = 0;
00129 float sumPt2 = 0;
00130
00131 for(unsigned int k = 0 ; k < GammasPt->size() ; k++){
00132 float pt_k = (*GammasPt)[k];
00133 float phi_k = (*GammasdPhi)[k];
00134 if ((*GammasdPhi)[k] > TMath::Pi()) phi_k = (*GammasdPhi)[k] - 2*TMath::Pi();
00135 else if((*GammasdPhi)[k] < -TMath::Pi()) phi_k = (*GammasdPhi)[k] + 2*TMath::Pi();
00136 float eta_k = (*GammasdEta)[k];
00137 sumPt += pt_k;
00138 sumPt2 += (pt_k*pt_k);
00139 dEta += (pt_k*eta_k);
00140 dEta2 += (pt_k*eta_k*eta_k);
00141 dPhi += (pt_k*phi_k);
00142 dPhi2 += (pt_k*phi_k*phi_k);
00143 }
00144
00145 GammadPt_ = sumPt/TauPt;
00146
00147 if(sumPt>0){
00148 dEta /= sumPt;
00149 dPhi /= sumPt;
00150 dEta2 /= sumPt;
00151 dPhi2 /= sumPt;
00152
00153 }
00154
00155
00156
00157
00158 GammadEta_ = TMath::Sqrt(dEta2)*TMath::Sqrt(GammadPt_)*TauPt;
00159 GammadPhi_ = TMath::Sqrt(dPhi2)*TMath::Sqrt(GammadPt_)*TauPt;
00160
00161
00162 if( TauSignalPFChargedCands==3 )
00163 mva = 1.0;
00164 else if( TauSignalPFChargedCands==1 && TauSignalPFGammaCands==0){
00165 if(TMath::Abs(TauEta)<1.5)
00166 mva = fTMVAReader_[0]->EvaluateMVA( methodName_ );
00167 else
00168 mva = fTMVAReader_[3]->EvaluateMVA( methodName_ );
00169 }
00170 else if( TauSignalPFChargedCands==1 && TauSignalPFGammaCands>0 && TauHasGsf>0.5){
00171 if(TMath::Abs(TauEta)<1.5)
00172 mva = fTMVAReader_[1]->EvaluateMVA( methodName_ );
00173 else
00174 mva = fTMVAReader_[4]->EvaluateMVA( methodName_ );
00175 }
00176 else if( TauSignalPFChargedCands==1 && TauSignalPFGammaCands>0 && TauHasGsf<0.5){
00177 if(TMath::Abs(TauEta)<1.5)
00178 mva = fTMVAReader_[2]->EvaluateMVA( methodName_ );
00179 else
00180 mva = fTMVAReader_[5]->EvaluateMVA( methodName_ );
00181 }
00182 else{
00183 mva = -99;
00184 }
00185
00186 return mva;
00187
00188 }
00189
00190 double AntiElectronIDMVA::MVAValue(Float_t TauEta, Float_t TauPt,
00191 Float_t TauSignalPFChargedCands, Float_t TauSignalPFGammaCands,
00192 Float_t TauLeadPFChargedHadrMva,
00193 Float_t TauLeadPFChargedHadrHoP, Float_t TauLeadPFChargedHadrEoP,
00194 Float_t TauHasGsf, Float_t TauVisMass, Float_t TauEmFraction,
00195 Float_t GammaEtaMom, Float_t GammaPhiMom, Float_t GammaEnFrac
00196 ){
00197
00198 if (!isInitialized_) {
00199 std::cout << "Error: AntiElectronMVA with method 2 not properly initialized.\n";
00200 return -999;
00201 }
00202
00203
00204 double mva;
00205
00206 TauVisMass_ = TauVisMass;
00207 TauLeadPFChargedHadrMva_ = TMath::Max(TauLeadPFChargedHadrMva,float(-1.0));
00208 TauLeadPFChargedHadrHoP_ = TauLeadPFChargedHadrHoP;
00209 TauLeadPFChargedHadrEoP_ = TauLeadPFChargedHadrEoP;
00210 TauEmFraction_ = TMath::Max(TauEmFraction,float(0.0));
00211 GammadPt_ = GammaEnFrac;
00212 GammadEta_ = GammaEtaMom;
00213 GammadPhi_ = GammaPhiMom;
00214
00215 if( TauSignalPFChargedCands==3 )
00216 mva = 1.0;
00217 else if( TauSignalPFChargedCands==1 && TauSignalPFGammaCands==0){
00218 if(TMath::Abs(TauEta)<1.5)
00219 mva = fTMVAReader_[0]->EvaluateMVA( methodName_ );
00220 else
00221 mva = fTMVAReader_[3]->EvaluateMVA( methodName_ );
00222 }
00223 else if( TauSignalPFChargedCands==1 && TauSignalPFGammaCands>0 && TauHasGsf>0.5){
00224 if(TMath::Abs(TauEta)<1.5)
00225 mva = fTMVAReader_[1]->EvaluateMVA( methodName_ );
00226 else
00227 mva = fTMVAReader_[4]->EvaluateMVA( methodName_ );
00228 }
00229 else if( TauSignalPFChargedCands==1 && TauSignalPFGammaCands>0 && TauHasGsf<0.5){
00230 if(TMath::Abs(TauEta)<1.5)
00231 mva = fTMVAReader_[2]->EvaluateMVA( methodName_ );
00232 else
00233 mva = fTMVAReader_[5]->EvaluateMVA( methodName_ );
00234 }
00235 else{
00236 mva = -99.;
00237 }
00238
00239 return mva;
00240
00241 }
00242
00243
00244
00245 double AntiElectronIDMVA::MVAValue(const reco::PFTauRef& thePFTauRef){
00246
00247 if (!isInitialized_) {
00248 std::cout << "Error: AntiElectronMVA with method 3 not properly initialized.\n";
00249 return -999;
00250 }
00251
00252 double mva;
00253
00254 TauVisMass_ = (*thePFTauRef).mass();
00255 TauLeadPFChargedHadrMva_ = TMath::Max((*thePFTauRef).electronPreIDOutput(),float(-1.0));
00256 TauLeadPFChargedHadrHoP_ = ((*thePFTauRef).leadPFChargedHadrCand())->hcalEnergy()/(*thePFTauRef).leadPFChargedHadrCand()->p();
00257 TauLeadPFChargedHadrEoP_ = ((*thePFTauRef).leadPFChargedHadrCand())->ecalEnergy()/(*thePFTauRef).leadPFChargedHadrCand()->p();
00258 TauEmFraction_ = TMath::Max((*thePFTauRef).emFraction(),float(0.0));
00259
00260 std::vector<float> GammasdEta;
00261 std::vector<float> GammasdPhi;
00262 std::vector<float> GammasPt;
00263
00264 for(unsigned int k = 0 ; k < ((*thePFTauRef).signalPFGammaCands()).size() ; k++){
00265 reco::PFCandidateRef gamma = ((*thePFTauRef).signalPFGammaCands()).at(k);
00266 if( ((*thePFTauRef).leadPFChargedHadrCand()).isNonnull() ){
00267 GammasdEta.push_back( gamma->eta() - (*thePFTauRef).leadPFChargedHadrCand()->eta() );
00268 GammasdPhi.push_back( gamma->phi() - (*thePFTauRef).leadPFChargedHadrCand()->phi() );
00269 }
00270 else{
00271 GammasdEta.push_back( gamma->eta() - (*thePFTauRef).eta() );
00272 GammasdPhi.push_back( gamma->phi() - (*thePFTauRef).phi() );
00273 }
00274 GammasPt.push_back( gamma->pt() );
00275 }
00276
00277 float sumPt = 0;
00278 float dEta = 0;
00279 float dEta2 = 0;
00280 float dPhi = 0;
00281 float dPhi2 = 0;
00282 float sumPt2 = 0;
00283
00284 for(unsigned int k = 0 ; k < GammasPt.size() ; k++){
00285 float pt_k = GammasPt[k];
00286 float phi_k = GammasdPhi[k];
00287 if (GammasdPhi[k] > TMath::Pi()) phi_k = GammasdPhi[k] - 2*TMath::Pi();
00288 else if(GammasdPhi[k] < -TMath::Pi()) phi_k = GammasdPhi[k] + 2*TMath::Pi();
00289 float eta_k = GammasdEta[k];
00290 sumPt += pt_k;
00291 sumPt2 += (pt_k*pt_k);
00292 dEta += (pt_k*eta_k);
00293 dEta2 += (pt_k*eta_k*eta_k);
00294 dPhi += (pt_k*phi_k);
00295 dPhi2 += (pt_k*phi_k*phi_k);
00296 }
00297
00298 GammadPt_ = sumPt/(*thePFTauRef).pt();
00299
00300 if(sumPt>0){
00301 dEta /= sumPt;
00302 dPhi /= sumPt;
00303 dEta2 /= sumPt;
00304 dPhi2 /= sumPt;
00305 }
00306
00307
00308
00309
00310 GammadEta_ = TMath::Sqrt(dEta2)*TMath::Sqrt(GammadPt_)*(*thePFTauRef).pt();
00311 GammadPhi_ = TMath::Sqrt(dPhi2)*TMath::Sqrt(GammadPt_)*(*thePFTauRef).pt();
00312
00313 if( ((*thePFTauRef).signalPFChargedHadrCands()).size() == 3)
00314 mva = 1.0;
00315 else if( ((*thePFTauRef).signalPFChargedHadrCands()).size()==1 && ((*thePFTauRef).signalPFGammaCands()).size()==0){
00316 if(TMath::Abs((*thePFTauRef).eta())<1.5)
00317 mva = fTMVAReader_[0]->EvaluateMVA( methodName_ );
00318 else
00319 mva = fTMVAReader_[3]->EvaluateMVA( methodName_ );
00320 }
00321 else if( ((*thePFTauRef).signalPFChargedHadrCands()).size()==1 && ((*thePFTauRef).signalPFGammaCands()).size()>0 && (((*thePFTauRef).leadPFChargedHadrCand())->gsfTrackRef()).isNonnull()){
00322 if(TMath::Abs((*thePFTauRef).eta())<1.5)
00323 mva = fTMVAReader_[1]->EvaluateMVA( methodName_ );
00324 else
00325 mva = fTMVAReader_[4]->EvaluateMVA( methodName_ );
00326 }
00327 else if( ((*thePFTauRef).signalPFChargedHadrCands()).size()==1 && ((*thePFTauRef).signalPFGammaCands()).size()>0 && !(((*thePFTauRef).leadPFChargedHadrCand())->gsfTrackRef()).isNonnull()){
00328 if(TMath::Abs((*thePFTauRef).eta())<1.5)
00329 mva = fTMVAReader_[2]->EvaluateMVA( methodName_ );
00330 else
00331 mva = fTMVAReader_[5]->EvaluateMVA( methodName_ );
00332 }
00333 else{
00334 mva = -99;
00335 }
00336
00337 return mva;
00338
00339 }