00001 #include <TFile.h>
00002 #include <TMath.h>
00003 #include "RecoTauTag/RecoTau/interface/AntiElectronIDMVA2.h"
00004 #include "RecoTauTag/RecoTau/interface/TMVAZipReader.h"
00005 #include "FWCore/Utilities/interface/Exception.h"
00006
00007 AntiElectronIDMVA2::AntiElectronIDMVA2()
00008 : isInitialized_(kFALSE),
00009 methodName_("BDT")
00010 {
00011 for ( unsigned i = 0; i < 10; ++i ) {
00012 fTMVAReader_[i] = 0;
00013 }
00014
00015 verbosity_ = 1;
00016 }
00017
00018 AntiElectronIDMVA2::~AntiElectronIDMVA2()
00019 {
00020 for ( unsigned i = 0; i < 10; ++i ) {
00021 if ( fTMVAReader_[i] ) delete fTMVAReader_[i];
00022 }
00023 }
00024
00025 enum { k_NoEleMatch_BL,
00026 k_woG_BL,
00027 k_wGwoGSF_BL,
00028 k_wGwGSFwoPFMVA_BL,
00029 k_wGwGSFwPFMVA_BL,
00030 k_NoEleMatch_EC,
00031 k_woG_EC,
00032 k_wGwoGSF_EC,
00033 k_wGwGSFwoPFMVA_EC,
00034 k_wGwGSFwPFMVA_EC };
00035
00036
00037 void AntiElectronIDMVA2::Initialize_from_file(const std::string& methodName,
00038 const std::string& oneProngNoEleMatch_BL,
00039 const std::string& oneProng0Pi0_BL,
00040 const std::string& oneProng1pi0woGSF_BL,
00041 const std::string& oneProng1pi0wGSFwoPfEleMva_BL,
00042 const std::string& oneProng1pi0wGSFwPfEleMva_BL,
00043 const std::string& oneProngNoEleMatch_EC,
00044 const std::string& oneProng0Pi0_EC,
00045 const std::string& oneProng1pi0woGSF_EC,
00046 const std::string& oneProng1pi0wGSFwoPfEleMva_EC,
00047 const std::string& oneProng1pi0wGSFwPfEleMva_EC)
00048 {
00049 for ( unsigned i = 0; i < 10; ++i ) {
00050 if ( fTMVAReader_[i] ) delete fTMVAReader_[i];
00051 }
00052
00053 isInitialized_ = kTRUE;
00054 methodName_ = methodName;
00055
00056 bookMVAs();
00057
00058 reco::details::loadTMVAWeights(fTMVAReader_[k_NoEleMatch_BL], methodName_, oneProngNoEleMatch_BL);
00059 reco::details::loadTMVAWeights(fTMVAReader_[k_woG_BL], methodName_, oneProng0Pi0_BL);
00060 reco::details::loadTMVAWeights(fTMVAReader_[k_wGwoGSF_BL], methodName_, oneProng1pi0woGSF_BL);
00061 reco::details::loadTMVAWeights(fTMVAReader_[k_wGwGSFwoPFMVA_BL], methodName_, oneProng1pi0wGSFwoPfEleMva_BL);
00062 reco::details::loadTMVAWeights(fTMVAReader_[k_wGwGSFwPFMVA_BL], methodName_, oneProng1pi0wGSFwPfEleMva_BL);
00063 reco::details::loadTMVAWeights(fTMVAReader_[k_NoEleMatch_EC], methodName_, oneProngNoEleMatch_EC);
00064 reco::details::loadTMVAWeights(fTMVAReader_[k_woG_EC], methodName_, oneProng0Pi0_EC);
00065 reco::details::loadTMVAWeights(fTMVAReader_[k_wGwoGSF_EC], methodName_, oneProng1pi0woGSF_EC);
00066 reco::details::loadTMVAWeights(fTMVAReader_[k_wGwGSFwoPFMVA_EC], methodName_, oneProng1pi0wGSFwoPfEleMva_EC);
00067 reco::details::loadTMVAWeights(fTMVAReader_[k_wGwGSFwPFMVA_EC], methodName_, oneProng1pi0wGSFwPfEleMva_EC);
00068 }
00069
00070 void AntiElectronIDMVA2::Initialize_from_string(const std::string& methodName,
00071 const std::string& oneProngNoEleMatch_BL,
00072 const std::string& oneProng0Pi0_BL,
00073 const std::string& oneProng1pi0woGSF_BL,
00074 const std::string& oneProng1pi0wGSFwoPfEleMva_BL,
00075 const std::string& oneProng1pi0wGSFwPfEleMva_BL,
00076 const std::string& oneProngNoEleMatch_EC,
00077 const std::string& oneProng0Pi0_EC,
00078 const std::string& oneProng1pi0woGSF_EC,
00079 const std::string& oneProng1pi0wGSFwoPfEleMva_EC,
00080 const std::string& oneProng1pi0wGSFwPfEleMva_EC)
00081 {
00082 for ( unsigned i = 0; i < 10; ++i ) {
00083 if ( fTMVAReader_[i] ) delete fTMVAReader_[i];
00084 }
00085
00086 isInitialized_ = kTRUE;
00087 methodName_ = methodName;
00088
00089 bookMVAs();
00090
00091 int methodName_int = -1;
00092 if ( methodName_ == "BDT" ) methodName_int = TMVA::Types::kBDT;
00093 else throw cms::Exception("InvalidParameter")
00094 << "Invalid TMVA method name = " << methodName_ << " !!\n";
00095
00096 fTMVAReader_[k_NoEleMatch_BL]->BookMVA(methodName_int, oneProngNoEleMatch_BL.data());
00097 fTMVAReader_[k_woG_BL]->BookMVA(methodName_int, oneProng0Pi0_BL.data());
00098 fTMVAReader_[k_wGwoGSF_BL]->BookMVA(methodName_int, oneProng1pi0woGSF_BL.data());
00099 fTMVAReader_[k_wGwGSFwoPFMVA_BL]->BookMVA(methodName_int, oneProng1pi0wGSFwoPfEleMva_BL.data());
00100 fTMVAReader_[k_wGwGSFwPFMVA_BL]->BookMVA(methodName_int, oneProng1pi0wGSFwPfEleMva_BL.data());
00101 fTMVAReader_[k_NoEleMatch_EC]->BookMVA(methodName_int, oneProngNoEleMatch_EC.data());
00102 fTMVAReader_[k_woG_EC]->BookMVA(methodName_int, oneProng0Pi0_EC.data());
00103 fTMVAReader_[k_wGwoGSF_EC]->BookMVA(methodName_int, oneProng1pi0woGSF_EC.data());
00104 fTMVAReader_[k_wGwGSFwoPFMVA_EC]->BookMVA(methodName_int, oneProng1pi0wGSFwoPfEleMva_EC.data());
00105 fTMVAReader_[k_wGwGSFwPFMVA_EC]->BookMVA(methodName_int, oneProng1pi0wGSFwPfEleMva_EC.data());
00106 }
00107
00108 void AntiElectronIDMVA2::bookMVAs()
00109 {
00110
00111
00112 TMVA::Reader* readerNoEleMatch_BL = new TMVA::Reader( "!Color:Silent:Error" );
00113 readerNoEleMatch_BL->AddVariable("Tau_EtaAtEcalEntrance", &Tau_EtaAtEcalEntrance_);
00114 readerNoEleMatch_BL->AddVariable("Tau_Pt", &Tau_Pt_);
00115 readerNoEleMatch_BL->AddVariable("Tau_EmFraction", &Tau_EmFraction_);
00116 readerNoEleMatch_BL->AddVariable("Tau_NumGammaCands", &Tau_NumGammaCands_);
00117 readerNoEleMatch_BL->AddVariable("Tau_HadrHoP", &Tau_HadrHoP_);
00118 readerNoEleMatch_BL->AddVariable("Tau_HadrEoP", &Tau_HadrEoP_);
00119 readerNoEleMatch_BL->AddVariable("Tau_VisMass", &Tau_VisMass_);
00120 readerNoEleMatch_BL->AddVariable("Tau_GammaEtaMom", &Tau_GammaEtaMom_);
00121 readerNoEleMatch_BL->AddVariable("Tau_GammaPhiMom", &Tau_GammaPhiMom_);
00122 readerNoEleMatch_BL->AddVariable("Tau_GammaEnFrac", &Tau_GammaEnFrac_);
00123 readerNoEleMatch_BL->SetVerbose(verbosity_);
00124
00125 TMVA::Reader* readerwoG_BL = new TMVA::Reader( "!Color:Silent:Error" );
00126 readerwoG_BL->AddVariable("Elec_EtotOverPin", &Elec_EtotOverPin_);
00127 readerwoG_BL->AddVariable("Elec_LateBrem", &Elec_LateBrem_);
00128 readerwoG_BL->AddVariable("Elec_Fbrem", &Elec_Fbrem_);
00129 readerwoG_BL->AddVariable("Elec_Chi2KF", &Elec_Chi2KF_);
00130 readerwoG_BL->AddVariable("Elec_GSFTrackResol", &Elec_GSFTrackResol_);
00131 readerwoG_BL->AddVariable("Elec_GSFTracklnPt", &Elec_GSFTracklnPt_);
00132 readerwoG_BL->AddVariable("Elec_GSFTrackEta", &Elec_GSFTrackEta_);
00133 readerwoG_BL->AddVariable("Tau_EtaAtEcalEntrance", &Tau_EtaAtEcalEntrance_);
00134 readerwoG_BL->AddVariable("Tau_Pt", &Tau_Pt_);
00135 readerwoG_BL->AddVariable("Tau_EmFraction", &Tau_EmFraction_);
00136 readerwoG_BL->AddVariable("Tau_HadrHoP", &Tau_HadrHoP_);
00137 readerwoG_BL->AddVariable("Tau_HadrEoP", &Tau_HadrEoP_);
00138 readerwoG_BL->AddVariable("Tau_VisMass", &Tau_VisMass_);
00139 readerwoG_BL->SetVerbose(verbosity_);
00140
00141 TMVA::Reader* readerwGwoGSF_BL = new TMVA::Reader( "!Color:Silent:Error" );
00142 readerwGwoGSF_BL->AddVariable("Elec_EtotOverPin", &Elec_EtotOverPin_);
00143 readerwGwoGSF_BL->AddVariable("Elec_EgammaOverPdif", &Elec_EgammaOverPdif_);
00144 readerwGwoGSF_BL->AddVariable("Elec_LateBrem", &Elec_LateBrem_);
00145 readerwGwoGSF_BL->AddVariable("Elec_Fbrem", &Elec_Fbrem_);
00146 readerwGwoGSF_BL->AddVariable("Elec_Chi2GSF", &Elec_Chi2GSF_);
00147 readerwGwoGSF_BL->AddVariable("Elec_NumHits", &Elec_NumHits_);
00148 readerwGwoGSF_BL->AddVariable("Elec_GSFTrackResol", &Elec_GSFTrackResol_);
00149 readerwGwoGSF_BL->AddVariable("Elec_GSFTracklnPt", &Elec_GSFTracklnPt_);
00150 readerwGwoGSF_BL->AddVariable("Elec_GSFTrackEta", &Elec_GSFTrackEta_);
00151 readerwGwoGSF_BL->AddVariable("Tau_EtaAtEcalEntrance", &Tau_EtaAtEcalEntrance_);
00152 readerwGwoGSF_BL->AddVariable("Tau_Pt", &Tau_Pt_);
00153 readerwGwoGSF_BL->AddVariable("Tau_EmFraction", &Tau_EmFraction_);
00154 readerwGwoGSF_BL->AddVariable("Tau_NumGammaCands", &Tau_NumGammaCands_);
00155 readerwGwoGSF_BL->AddVariable("Tau_HadrHoP", &Tau_HadrHoP_);
00156 readerwGwoGSF_BL->AddVariable("Tau_HadrEoP", &Tau_HadrEoP_);
00157 readerwGwoGSF_BL->AddVariable("Tau_VisMass", &Tau_VisMass_);
00158 readerwGwoGSF_BL->AddVariable("Tau_GammaEtaMom", &Tau_GammaEtaMom_);
00159 readerwGwoGSF_BL->AddVariable("Tau_GammaPhiMom", &Tau_GammaPhiMom_);
00160 readerwGwoGSF_BL->AddVariable("Tau_GammaEnFrac", &Tau_GammaEnFrac_);
00161 readerwGwoGSF_BL->SetVerbose(verbosity_);
00162
00163 TMVA::Reader* readerwGwGSFwoPFMVA_BL = new TMVA::Reader( "!Color:Silent:Error" );
00164 readerwGwGSFwoPFMVA_BL->AddVariable("Elec_Fbrem", &Elec_Fbrem_);
00165 readerwGwGSFwoPFMVA_BL->AddVariable("Elec_Chi2KF", &Elec_Chi2KF_);
00166 readerwGwGSFwoPFMVA_BL->AddVariable("Elec_Chi2GSF", &Elec_Chi2GSF_);
00167 readerwGwGSFwoPFMVA_BL->AddVariable("Elec_NumHits", &Elec_NumHits_);
00168 readerwGwGSFwoPFMVA_BL->AddVariable("Elec_GSFTrackResol", &Elec_GSFTrackResol_);
00169 readerwGwGSFwoPFMVA_BL->AddVariable("Elec_GSFTracklnPt", &Elec_GSFTracklnPt_);
00170 readerwGwGSFwoPFMVA_BL->AddVariable("Elec_GSFTrackEta", &Elec_GSFTrackEta_);
00171 readerwGwGSFwoPFMVA_BL->AddVariable("Tau_EtaAtEcalEntrance", &Tau_EtaAtEcalEntrance_);
00172 readerwGwGSFwoPFMVA_BL->AddVariable("Tau_Pt", &Tau_Pt_);
00173 readerwGwGSFwoPFMVA_BL->AddVariable("Tau_EmFraction", &Tau_EmFraction_);
00174 readerwGwGSFwoPFMVA_BL->AddVariable("Tau_NumGammaCands", &Tau_NumGammaCands_);
00175 readerwGwGSFwoPFMVA_BL->AddVariable("Tau_HadrHoP", &Tau_HadrHoP_);
00176 readerwGwGSFwoPFMVA_BL->AddVariable("Tau_HadrEoP", &Tau_HadrEoP_);
00177 readerwGwGSFwoPFMVA_BL->AddVariable("Tau_VisMass", &Tau_VisMass_);
00178 readerwGwGSFwoPFMVA_BL->AddVariable("Tau_GammaEtaMom", &Tau_GammaEtaMom_);
00179 readerwGwGSFwoPFMVA_BL->AddVariable("Tau_GammaPhiMom", &Tau_GammaPhiMom_);
00180 readerwGwGSFwoPFMVA_BL->AddVariable("Tau_GammaEnFrac", &Tau_GammaEnFrac_);
00181 readerwGwGSFwoPFMVA_BL->SetVerbose(verbosity_);
00182
00183 TMVA::Reader* readerwGwGSFwPFMVA_BL = new TMVA::Reader( "!Color:Silent:Error" );
00184 readerwGwGSFwPFMVA_BL->AddVariable("Elec_EtotOverPin", &Elec_EtotOverPin_);
00185 readerwGwGSFwPFMVA_BL->AddVariable("Elec_EeOverPout", &Elec_EeOverPout_);
00186 readerwGwGSFwPFMVA_BL->AddVariable("Elec_LateBrem", &Elec_LateBrem_);
00187 readerwGwGSFwPFMVA_BL->AddVariable("Elec_Chi2GSF", &Elec_Chi2GSF_);
00188 readerwGwGSFwPFMVA_BL->AddVariable("Elec_NumHits", &Elec_NumHits_);
00189 readerwGwGSFwPFMVA_BL->AddVariable("Elec_GSFTrackResol", &Elec_GSFTrackResol_);
00190 readerwGwGSFwPFMVA_BL->AddVariable("Elec_GSFTracklnPt", &Elec_GSFTracklnPt_);
00191 readerwGwGSFwPFMVA_BL->AddVariable("Elec_GSFTrackEta", &Elec_GSFTrackEta_);
00192 readerwGwGSFwPFMVA_BL->AddVariable("Tau_EtaAtEcalEntrance", &Tau_EtaAtEcalEntrance_);
00193 readerwGwGSFwPFMVA_BL->AddVariable("Tau_Pt", &Tau_Pt_);
00194 readerwGwGSFwPFMVA_BL->AddVariable("Tau_EmFraction", &Tau_EmFraction_);
00195 readerwGwGSFwPFMVA_BL->AddVariable("Tau_NumGammaCands", &Tau_NumGammaCands_);
00196 readerwGwGSFwPFMVA_BL->AddVariable("Tau_HadrHoP", &Tau_HadrHoP_);
00197 readerwGwGSFwPFMVA_BL->AddVariable("Tau_HadrEoP", &Tau_HadrEoP_);
00198 readerwGwGSFwPFMVA_BL->AddVariable("Tau_VisMass", &Tau_VisMass_);
00199 readerwGwGSFwPFMVA_BL->AddVariable("Tau_GammaEtaMom", &Tau_GammaEtaMom_);
00200 readerwGwGSFwPFMVA_BL->AddVariable("Tau_GammaPhiMom", &Tau_GammaPhiMom_);
00201 readerwGwGSFwPFMVA_BL->AddVariable("Tau_GammaEnFrac", &Tau_GammaEnFrac_);
00202 readerwGwGSFwPFMVA_BL->SetVerbose(verbosity_);
00203
00204 TMVA::Reader* readerNoEleMatch_EC = new TMVA::Reader( "!Color:Silent:Error" );
00205 readerNoEleMatch_EC->AddVariable("Tau_EtaAtEcalEntrance", &Tau_EtaAtEcalEntrance_);
00206 readerNoEleMatch_EC->AddVariable("Tau_Pt", &Tau_Pt_);
00207 readerNoEleMatch_EC->AddVariable("Tau_EmFraction", &Tau_EmFraction_);
00208 readerNoEleMatch_EC->AddVariable("Tau_NumGammaCands", &Tau_NumGammaCands_);
00209 readerNoEleMatch_EC->AddVariable("Tau_HadrHoP", &Tau_HadrHoP_);
00210 readerNoEleMatch_EC->AddVariable("Tau_HadrEoP", &Tau_HadrEoP_);
00211 readerNoEleMatch_EC->AddVariable("Tau_VisMass", &Tau_VisMass_);
00212 readerNoEleMatch_EC->AddVariable("Tau_GammaEtaMom", &Tau_GammaEtaMom_);
00213 readerNoEleMatch_EC->AddVariable("Tau_GammaPhiMom", &Tau_GammaPhiMom_);
00214 readerNoEleMatch_EC->AddVariable("Tau_GammaEnFrac", &Tau_GammaEnFrac_);
00215 readerNoEleMatch_EC->SetVerbose(verbosity_);
00216
00217 TMVA::Reader* readerwoG_EC = new TMVA::Reader( "!Color:Silent:Error" );
00218 readerwoG_EC->AddVariable("Elec_EtotOverPin", &Elec_EtotOverPin_);
00219 readerwoG_EC->AddVariable("Elec_LateBrem", &Elec_LateBrem_);
00220 readerwoG_EC->AddVariable("Elec_Fbrem", &Elec_Fbrem_);
00221 readerwoG_EC->AddVariable("Elec_Chi2KF", &Elec_Chi2KF_);
00222 readerwoG_EC->AddVariable("Elec_GSFTrackResol", &Elec_GSFTrackResol_);
00223 readerwoG_EC->AddVariable("Elec_GSFTracklnPt", &Elec_GSFTracklnPt_);
00224 readerwoG_EC->AddVariable("Elec_GSFTrackEta", &Elec_GSFTrackEta_);
00225 readerwoG_EC->AddVariable("Tau_EtaAtEcalEntrance", &Tau_EtaAtEcalEntrance_);
00226 readerwoG_EC->AddVariable("Tau_Pt", &Tau_Pt_);
00227 readerwoG_EC->AddVariable("Tau_EmFraction", &Tau_EmFraction_);
00228 readerwoG_EC->AddVariable("Tau_HadrHoP", &Tau_HadrHoP_);
00229 readerwoG_EC->AddVariable("Tau_HadrEoP", &Tau_HadrEoP_);
00230 readerwoG_EC->AddVariable("Tau_VisMass", &Tau_VisMass_);
00231 readerwoG_EC->SetVerbose(verbosity_);
00232
00233 TMVA::Reader* readerwGwoGSF_EC = new TMVA::Reader( "!Color:Silent:Error" );
00234 readerwGwoGSF_EC->AddVariable("Elec_EtotOverPin", &Elec_EtotOverPin_);
00235 readerwGwoGSF_EC->AddVariable("Elec_EgammaOverPdif", &Elec_EgammaOverPdif_);
00236 readerwGwoGSF_EC->AddVariable("Elec_LateBrem", &Elec_LateBrem_);
00237 readerwGwoGSF_EC->AddVariable("Elec_Fbrem", &Elec_Fbrem_);
00238 readerwGwoGSF_EC->AddVariable("Elec_Chi2GSF", &Elec_Chi2GSF_);
00239 readerwGwoGSF_EC->AddVariable("Elec_NumHits", &Elec_NumHits_);
00240 readerwGwoGSF_EC->AddVariable("Elec_GSFTrackResol", &Elec_GSFTrackResol_);
00241 readerwGwoGSF_EC->AddVariable("Elec_GSFTracklnPt", &Elec_GSFTracklnPt_);
00242 readerwGwoGSF_EC->AddVariable("Elec_GSFTrackEta", &Elec_GSFTrackEta_);
00243 readerwGwoGSF_EC->AddVariable("Tau_EtaAtEcalEntrance", &Tau_EtaAtEcalEntrance_);
00244 readerwGwoGSF_EC->AddVariable("Tau_Pt", &Tau_Pt_);
00245 readerwGwoGSF_EC->AddVariable("Tau_EmFraction", &Tau_EmFraction_);
00246 readerwGwoGSF_EC->AddVariable("Tau_NumGammaCands", &Tau_NumGammaCands_);
00247 readerwGwoGSF_EC->AddVariable("Tau_HadrHoP", &Tau_HadrHoP_);
00248 readerwGwoGSF_EC->AddVariable("Tau_HadrEoP", &Tau_HadrEoP_);
00249 readerwGwoGSF_EC->AddVariable("Tau_VisMass", &Tau_VisMass_);
00250 readerwGwoGSF_EC->AddVariable("Tau_GammaEtaMom", &Tau_GammaEtaMom_);
00251 readerwGwoGSF_EC->AddVariable("Tau_GammaPhiMom", &Tau_GammaPhiMom_);
00252 readerwGwoGSF_EC->AddVariable("Tau_GammaEnFrac", &Tau_GammaEnFrac_);
00253 readerwGwoGSF_EC->SetVerbose(verbosity_);
00254
00255 TMVA::Reader* readerwGwGSFwoPFMVA_EC = new TMVA::Reader( "!Color:Silent:Error" );
00256 readerwGwGSFwoPFMVA_EC->AddVariable("Elec_Fbrem", &Elec_Fbrem_);
00257 readerwGwGSFwoPFMVA_EC->AddVariable("Elec_Chi2KF", &Elec_Chi2KF_);
00258 readerwGwGSFwoPFMVA_EC->AddVariable("Elec_Chi2GSF", &Elec_Chi2GSF_);
00259 readerwGwGSFwoPFMVA_EC->AddVariable("Elec_NumHits", &Elec_NumHits_);
00260 readerwGwGSFwoPFMVA_EC->AddVariable("Elec_GSFTrackResol", &Elec_GSFTrackResol_);
00261 readerwGwGSFwoPFMVA_EC->AddVariable("Elec_GSFTracklnPt", &Elec_GSFTracklnPt_);
00262 readerwGwGSFwoPFMVA_EC->AddVariable("Elec_GSFTrackEta", &Elec_GSFTrackEta_);
00263 readerwGwGSFwoPFMVA_EC->AddVariable("Tau_EtaAtEcalEntrance", &Tau_EtaAtEcalEntrance_);
00264 readerwGwGSFwoPFMVA_EC->AddVariable("Tau_Pt", &Tau_Pt_);
00265 readerwGwGSFwoPFMVA_EC->AddVariable("Tau_EmFraction", &Tau_EmFraction_);
00266 readerwGwGSFwoPFMVA_EC->AddVariable("Tau_NumGammaCands", &Tau_NumGammaCands_);
00267 readerwGwGSFwoPFMVA_EC->AddVariable("Tau_HadrHoP", &Tau_HadrHoP_);
00268 readerwGwGSFwoPFMVA_EC->AddVariable("Tau_HadrEoP", &Tau_HadrEoP_);
00269 readerwGwGSFwoPFMVA_EC->AddVariable("Tau_VisMass", &Tau_VisMass_);
00270 readerwGwGSFwoPFMVA_EC->AddVariable("Tau_GammaEtaMom", &Tau_GammaEtaMom_);
00271 readerwGwGSFwoPFMVA_EC->AddVariable("Tau_GammaPhiMom", &Tau_GammaPhiMom_);
00272 readerwGwGSFwoPFMVA_EC->AddVariable("Tau_GammaEnFrac", &Tau_GammaEnFrac_);
00273 readerwGwGSFwoPFMVA_EC->SetVerbose(verbosity_);
00274
00275 TMVA::Reader* readerwGwGSFwPFMVA_EC = new TMVA::Reader( "!Color:Silent:Error" );
00276 readerwGwGSFwPFMVA_EC->AddVariable("Elec_EtotOverPin", &Elec_EtotOverPin_);
00277 readerwGwGSFwPFMVA_EC->AddVariable("Elec_EeOverPout", &Elec_EeOverPout_);
00278 readerwGwGSFwPFMVA_EC->AddVariable("Elec_LateBrem", &Elec_LateBrem_);
00279 readerwGwGSFwPFMVA_EC->AddVariable("Elec_Chi2GSF", &Elec_Chi2GSF_);
00280 readerwGwGSFwPFMVA_EC->AddVariable("Elec_NumHits", &Elec_NumHits_);
00281 readerwGwGSFwPFMVA_EC->AddVariable("Elec_GSFTrackResol", &Elec_GSFTrackResol_);
00282 readerwGwGSFwPFMVA_EC->AddVariable("Elec_GSFTracklnPt", &Elec_GSFTracklnPt_);
00283 readerwGwGSFwPFMVA_EC->AddVariable("Elec_GSFTrackEta", &Elec_GSFTrackEta_);
00284 readerwGwGSFwPFMVA_EC->AddVariable("Tau_EtaAtEcalEntrance", &Tau_EtaAtEcalEntrance_);
00285 readerwGwGSFwPFMVA_EC->AddVariable("Tau_Pt", &Tau_Pt_);
00286 readerwGwGSFwPFMVA_EC->AddVariable("Tau_EmFraction", &Tau_EmFraction_);
00287 readerwGwGSFwPFMVA_EC->AddVariable("Tau_NumGammaCands", &Tau_NumGammaCands_);
00288 readerwGwGSFwPFMVA_EC->AddVariable("Tau_HadrHoP", &Tau_HadrHoP_);
00289 readerwGwGSFwPFMVA_EC->AddVariable("Tau_HadrEoP", &Tau_HadrEoP_);
00290 readerwGwGSFwPFMVA_EC->AddVariable("Tau_VisMass", &Tau_VisMass_);
00291 readerwGwGSFwPFMVA_EC->AddVariable("Tau_GammaEtaMom", &Tau_GammaEtaMom_);
00292 readerwGwGSFwPFMVA_EC->AddVariable("Tau_GammaPhiMom", &Tau_GammaPhiMom_);
00293 readerwGwGSFwPFMVA_EC->AddVariable("Tau_GammaEnFrac", &Tau_GammaEnFrac_);
00294 readerwGwGSFwPFMVA_EC->SetVerbose(verbosity_);
00295
00296 fTMVAReader_[k_NoEleMatch_BL] = readerNoEleMatch_BL;
00297 fTMVAReader_[k_woG_BL] = readerwoG_BL;
00298 fTMVAReader_[k_wGwoGSF_BL] = readerwGwoGSF_BL;
00299 fTMVAReader_[k_wGwGSFwoPFMVA_BL] = readerwGwGSFwoPFMVA_BL;
00300 fTMVAReader_[k_wGwGSFwPFMVA_BL] = readerwGwGSFwPFMVA_BL;
00301 fTMVAReader_[k_NoEleMatch_EC] = readerNoEleMatch_EC;
00302 fTMVAReader_[k_woG_EC] = readerwoG_EC;
00303 fTMVAReader_[k_wGwoGSF_EC] = readerwGwoGSF_EC;
00304 fTMVAReader_[k_wGwGSFwoPFMVA_EC] = readerwGwGSFwoPFMVA_EC;
00305 fTMVAReader_[k_wGwGSFwPFMVA_EC] = readerwGwGSFwPFMVA_EC;
00306 }
00307
00308 double AntiElectronIDMVA2::MVAValue(Float_t TauEtaAtEcalEntrance,
00309 Float_t TauPhi,
00310 Float_t TauPt,
00311 Float_t TauSignalPFChargedCands,
00312 Float_t TauSignalPFGammaCands,
00313 Float_t TauLeadPFChargedHadrHoP,
00314 Float_t TauLeadPFChargedHadrEoP,
00315 Float_t TauHasGsf,
00316 Float_t TauVisMass,
00317 Float_t TauEmFraction,
00318 const std::vector<Float_t>& GammasdEta,
00319 const std::vector<Float_t>& GammasdPhi,
00320 const std::vector<Float_t>& GammasPt,
00321 Float_t ElecEta,
00322 Float_t ElecPhi,
00323 Float_t ElecPt,
00324 Float_t ElecPFMvaOutput,
00325 Float_t ElecEe,
00326 Float_t ElecEgamma,
00327 Float_t ElecPin,
00328 Float_t ElecPout,
00329 Float_t ElecEarlyBrem,
00330 Float_t ElecLateBrem,
00331 Float_t ElecFbrem,
00332 Float_t ElecChi2KF,
00333 Float_t ElecChi2GSF,
00334 Float_t ElecNumHits,
00335 Float_t ElecGSFTrackResol,
00336 Float_t ElecGSFTracklnPt,
00337 Float_t ElecGSFTrackEta)
00338 {
00339 double sumPt = 0.;
00340 double dEta = 0.;
00341 double dEta2 = 0.;
00342 double dPhi = 0.;
00343 double dPhi2 = 0.;
00344 double sumPt2 = 0.;
00345 for ( unsigned int i = 0 ; i < GammasPt.size() ; ++i ) {
00346 double pt_i = GammasPt[i];
00347 double phi_i = GammasdPhi[i];
00348 if ( GammasdPhi[i] > TMath::Pi() ) phi_i = GammasdPhi[i] - 2*TMath::Pi();
00349 else if ( GammasdPhi[i] < -TMath::Pi() ) phi_i = GammasdPhi[i] + 2*TMath::Pi();
00350 double eta_i = GammasdEta[i];
00351 sumPt += pt_i;
00352 sumPt2 += (pt_i*pt_i);
00353 dEta += (pt_i*eta_i);
00354 dEta2 += (pt_i*eta_i*eta_i);
00355 dPhi += (pt_i*phi_i);
00356 dPhi2 += (pt_i*phi_i*phi_i);
00357 }
00358
00359 Float_t GammaEnFrac = sumPt/TauPt;
00360
00361 if ( sumPt > 0. ) {
00362 dEta /= sumPt;
00363 dPhi /= sumPt;
00364 dEta2 /= sumPt;
00365 dPhi2 /= sumPt;
00366 }
00367
00368 Float_t GammaEtaMom = TMath::Sqrt(dEta2)*TMath::Sqrt(GammaEnFrac)*TauPt;
00369 Float_t GammaPhiMom = TMath::Sqrt(dPhi2)*TMath::Sqrt(GammaEnFrac)*TauPt;
00370
00371 return MVAValue(TauEtaAtEcalEntrance,
00372 TauPhi,
00373 TauPt,
00374 TauSignalPFChargedCands,
00375 TauSignalPFGammaCands,
00376 TauLeadPFChargedHadrHoP,
00377 TauLeadPFChargedHadrEoP,
00378 TauHasGsf,
00379 TauVisMass,
00380 TauEmFraction,
00381 GammaEtaMom,
00382 GammaPhiMom,
00383 GammaEnFrac,
00384 ElecEta,
00385 ElecPhi,
00386 ElecPt,
00387 ElecPFMvaOutput,
00388 ElecEe,
00389 ElecEgamma,
00390 ElecPin,
00391 ElecPout,
00392 ElecEarlyBrem,
00393 ElecLateBrem,
00394 ElecFbrem,
00395 ElecChi2KF,
00396 ElecChi2GSF,
00397 ElecNumHits,
00398 ElecGSFTrackResol,
00399 ElecGSFTracklnPt,
00400 ElecGSFTrackEta);
00401 }
00402
00403 double AntiElectronIDMVA2::MVAValue(Float_t TauEtaAtEcalEntrance,
00404 Float_t TauPhi,
00405 Float_t TauPt,
00406 Float_t TauSignalPFChargedCands,
00407 Float_t TauSignalPFGammaCands,
00408 Float_t TauLeadPFChargedHadrHoP,
00409 Float_t TauLeadPFChargedHadrEoP,
00410 Float_t TauHasGsf,
00411 Float_t TauVisMass,
00412 Float_t TauEmFraction,
00413 Float_t GammaEtaMom,
00414 Float_t GammaPhiMom,
00415 Float_t GammaEnFrac,
00416 Float_t ElecEta,
00417 Float_t ElecPhi,
00418 Float_t ElecPt,
00419 Float_t ElecPFMvaOutput,
00420 Float_t ElecEe,
00421 Float_t ElecEgamma,
00422 Float_t ElecPin,
00423 Float_t ElecPout,
00424 Float_t ElecEarlyBrem,
00425 Float_t ElecLateBrem,
00426 Float_t ElecFbrem,
00427 Float_t ElecChi2KF,
00428 Float_t ElecChi2GSF,
00429 Float_t ElecNumHits,
00430 Float_t ElecGSFTrackResol,
00431 Float_t ElecGSFTracklnPt,
00432 Float_t ElecGSFTrackEta)
00433 {
00434
00435 if ( !isInitialized_ ) {
00436 std::cout << "Error: AntiElectronMVA not properly initialized.\n";
00437 return -99.;
00438 }
00439
00440 Tau_EtaAtEcalEntrance_ = TauEtaAtEcalEntrance;
00441 Tau_Pt_ = TauPt;
00442 Tau_HasGsf_ = TauHasGsf;
00443 Tau_EmFraction_ = TMath::Max(TauEmFraction,float(0.0));
00444 Tau_NumChargedCands_ = TauSignalPFChargedCands;
00445 Tau_NumGammaCands_ = TauSignalPFGammaCands;
00446 Tau_HadrHoP_ = TauLeadPFChargedHadrHoP;
00447 Tau_HadrEoP_ = TauLeadPFChargedHadrEoP;
00448 Tau_VisMass_ = TauVisMass;
00449 Tau_GammaEtaMom_ = GammaEtaMom;
00450 Tau_GammaPhiMom_ = GammaPhiMom;
00451 Tau_GammaEnFrac_ = GammaEnFrac;
00452
00453 Elec_Eta_ = ElecEta;
00454 Elec_Pt_ = ElecPt;
00455 Elec_EtotOverPin_ = (ElecEe + ElecEgamma)/ElecPin;
00456 Elec_EgammaOverPdif_ = ElecEgamma/(ElecPin - ElecPout);
00457 Elec_EarlyBrem_ = ElecEarlyBrem;
00458 Elec_LateBrem_ = ElecLateBrem;
00459 Elec_Fbrem_ = ElecFbrem;
00460 Elec_Chi2KF_ = ElecChi2KF;
00461 Elec_Chi2GSF_ = ElecChi2GSF;
00462 Elec_NumHits_ = ElecNumHits;
00463 Elec_GSFTrackResol_ = ElecGSFTrackResol;
00464 Elec_GSFTracklnPt_ = ElecGSFTracklnPt;
00465 Elec_GSFTrackEta_ = ElecGSFTrackEta;
00466
00467 double mva = -99.;
00468 if ( Tau_NumChargedCands_ == 3 ) mva = 1.0;
00469 else if ( deltaR(TauEtaAtEcalEntrance, TauPhi, ElecEta, ElecPhi) > 0.3 ) {
00470 if ( TMath::Abs(TauEtaAtEcalEntrance) < 1.5 ) mva = fTMVAReader_[k_NoEleMatch_BL]->EvaluateMVA(methodName_);
00471 else mva = fTMVAReader_[k_NoEleMatch_EC]->EvaluateMVA(methodName_);
00472 } else if ( TauSignalPFGammaCands == 0 ) {
00473 if ( TMath::Abs(TauEtaAtEcalEntrance) < 1.5 ) mva = fTMVAReader_[k_woG_BL]->EvaluateMVA(methodName_);
00474 else mva = fTMVAReader_[k_woG_EC]->EvaluateMVA(methodName_);
00475 } else if ( TauSignalPFGammaCands > 0 && TauHasGsf < 0.5 ) {
00476 if ( TMath::Abs(TauEtaAtEcalEntrance) < 1.5 ) mva = fTMVAReader_[k_wGwoGSF_BL]->EvaluateMVA(methodName_);
00477 else mva = fTMVAReader_[k_wGwoGSF_EC]->EvaluateMVA(methodName_);
00478 } else if ( TauSignalPFGammaCands > 0 && TauHasGsf > 0.5 && ElecPFMvaOutput < -0.1 ) {
00479 if ( TMath::Abs(TauEtaAtEcalEntrance) < 1.5 ) mva = fTMVAReader_[k_wGwGSFwoPFMVA_BL]->EvaluateMVA(methodName_);
00480 else mva = fTMVAReader_[k_wGwGSFwoPFMVA_EC]->EvaluateMVA(methodName_);
00481 } else if ( TauSignalPFGammaCands > 0 && TauHasGsf > 0.5 && ElecPFMvaOutput > -0.1 ) {
00482 if ( TMath::Abs(TauEtaAtEcalEntrance) < 1.5 ) mva = fTMVAReader_[k_wGwGSFwPFMVA_BL]->EvaluateMVA(methodName_);
00483 else mva = fTMVAReader_[k_wGwGSFwPFMVA_EC]->EvaluateMVA(methodName_);
00484 }
00485
00486 return mva;
00487 }
00488
00489
00490 double AntiElectronIDMVA2::MVAValue(const reco::PFTau& thePFTau,
00491 const reco::GsfElectron& theGsfEle)
00492
00493 {
00494 float sumEtaTimesEnergy = 0;
00495 float sumEnergy = 0;
00496 Float_t TauEtaAtEcalEntrance = 0;
00497 for(unsigned int j = 0 ; j < (thePFTau.signalPFCands()).size() ; j++){
00498 reco::PFCandidateRef pfcandidate = (thePFTau.signalPFCands()).at(j);
00499 sumEtaTimesEnergy += pfcandidate->positionAtECALEntrance().eta()*pfcandidate->energy();
00500 sumEnergy += pfcandidate->energy();
00501 }
00502 if(sumEnergy>0)TauEtaAtEcalEntrance = sumEtaTimesEnergy/sumEnergy;
00503
00504 Float_t TauPhi = thePFTau.phi();
00505 Float_t TauPt = thePFTau.pt();
00506 Float_t TauSignalPFChargedCands = thePFTau.signalPFChargedHadrCands().size();
00507 Float_t TauSignalPFGammaCands = thePFTau.signalPFGammaCands().size();
00508 Float_t TauLeadPFChargedHadrHoP = 0.;
00509 Float_t TauLeadPFChargedHadrEoP = 0.;
00510 if ( thePFTau.leadPFChargedHadrCand()->p() > 0. ) {
00511 TauLeadPFChargedHadrHoP = thePFTau.leadPFChargedHadrCand()->hcalEnergy()/thePFTau.leadPFChargedHadrCand()->p();
00512 TauLeadPFChargedHadrEoP = thePFTau.leadPFChargedHadrCand()->ecalEnergy()/thePFTau.leadPFChargedHadrCand()->p();
00513 }
00514 Float_t TauHasGsf = thePFTau.leadPFChargedHadrCand()->gsfTrackRef().isNonnull();
00515 Float_t TauVisMass = thePFTau.mass();
00516 Float_t TauEmFraction = TMath::Max(thePFTau.emFraction(), (Float_t)0.);
00517 std::vector<Float_t> GammasdEta;
00518 std::vector<Float_t> GammasdPhi;
00519 std::vector<Float_t> GammasPt;
00520 for ( unsigned i = 0 ; i < thePFTau.signalPFGammaCands().size(); ++i ) {
00521 reco::PFCandidateRef gamma = thePFTau.signalPFGammaCands().at(i);
00522 if ( thePFTau.leadPFChargedHadrCand().isNonnull() ) {
00523 GammasdEta.push_back(gamma->eta() - thePFTau.leadPFChargedHadrCand()->eta());
00524 GammasdPhi.push_back(gamma->phi() - thePFTau.leadPFChargedHadrCand()->phi());
00525 } else {
00526 GammasdEta.push_back(gamma->eta() - thePFTau.eta());
00527 GammasdPhi.push_back(gamma->phi() - thePFTau.phi());
00528 }
00529 GammasPt.push_back(gamma->pt());
00530 }
00531
00532 Float_t ElecEta = theGsfEle.eta();
00533 Float_t ElecPhi = theGsfEle.phi();
00534 Float_t ElecPt = theGsfEle.pt();
00535 Float_t ElecPFMvaOutput = theGsfEle.mvaOutput().mva;
00536
00537 Float_t ElecEe = 0.;
00538 Float_t ElecEgamma = 0.;
00539 reco::SuperClusterRef pfSuperCluster = theGsfEle.pflowSuperCluster();
00540 if ( pfSuperCluster.isNonnull() && pfSuperCluster.isAvailable() ) {
00541 for ( reco::CaloCluster_iterator pfCluster = pfSuperCluster->clustersBegin();
00542 pfCluster != pfSuperCluster->clustersEnd(); ++pfCluster ) {
00543 double pfClusterEn = (*pfCluster)->energy();
00544 if ( pfCluster == pfSuperCluster->clustersBegin() ) Elec_Ee_ += pfClusterEn;
00545 else Elec_Egamma_ += pfClusterEn;
00546 }
00547 }
00548 Float_t ElecPin = TMath::Sqrt(theGsfEle.trackMomentumAtVtx().Mag2());
00549 Float_t ElecPout = TMath::Sqrt(theGsfEle.trackMomentumOut().Mag2());
00550 Float_t ElecEarlyBrem = theGsfEle.mvaInput().earlyBrem;
00551 Float_t ElecLateBrem = theGsfEle.mvaInput().lateBrem;
00552 Float_t ElecFbrem = theGsfEle.fbrem();
00553
00554 Float_t ElecChi2KF = -99.;
00555 Float_t ElecNumHits = -99.;
00556 if ( theGsfEle.closestCtfTrackRef().isNonnull() ) {
00557 ElecChi2KF = theGsfEle.closestCtfTrackRef()->normalizedChi2();
00558 ElecNumHits = theGsfEle.closestCtfTrackRef()->numberOfValidHits();
00559 }
00560
00561 Float_t ElecChi2GSF = -99.;
00562 Float_t ElecGSFTrackResol = -99.;
00563 Float_t ElecGSFTracklnPt = -99.;
00564 Float_t ElecGSFTrackEta = -99.;
00565 if ( theGsfEle.gsfTrack().isNonnull() ) {
00566 ElecChi2GSF = (theGsfEle).gsfTrack()->normalizedChi2();
00567 if ( theGsfEle.gsfTrack()->pt() > 0. ) {
00568 ElecGSFTrackResol = theGsfEle.gsfTrack()->ptError()/theGsfEle.gsfTrack()->pt();
00569 ElecGSFTracklnPt = log(theGsfEle.gsfTrack()->pt())*TMath::Ln10();
00570 }
00571 ElecGSFTrackEta = theGsfEle.gsfTrack()->eta();
00572 }
00573
00574 return MVAValue(TauEtaAtEcalEntrance,
00575 TauPhi,
00576 TauPt,
00577 TauSignalPFChargedCands,
00578 TauSignalPFGammaCands,
00579 TauLeadPFChargedHadrHoP,
00580 TauLeadPFChargedHadrEoP,
00581 TauHasGsf,
00582 TauVisMass,
00583 TauEmFraction,
00584 GammasdEta,
00585 GammasdPhi,
00586 GammasPt,
00587 ElecEta,
00588 ElecPhi,
00589 ElecPt,
00590 ElecPFMvaOutput,
00591 ElecEe,
00592 ElecEgamma,
00593 ElecPin,
00594 ElecPout,
00595 ElecEarlyBrem,
00596 ElecLateBrem,
00597 ElecFbrem,
00598 ElecChi2KF,
00599 ElecChi2GSF,
00600 ElecNumHits,
00601 ElecGSFTrackResol,
00602 ElecGSFTracklnPt,
00603 ElecGSFTrackEta);
00604 }
00605
00606 double AntiElectronIDMVA2::MVAValue(const reco::PFTau& thePFTau)
00607 {
00608 float sumEtaTimesEnergy = 0;
00609 float sumEnergy = 0;
00610 Float_t TauEtaAtEcalEntrance =0;
00611 for(unsigned int j = 0 ; j < (thePFTau.signalPFCands()).size() ; j++){
00612 reco::PFCandidateRef pfcandidate = (thePFTau.signalPFCands()).at(j);
00613 sumEtaTimesEnergy += pfcandidate->positionAtECALEntrance().eta()*pfcandidate->energy();
00614 sumEnergy += pfcandidate->energy();
00615 }
00616 if(sumEnergy>0)TauEtaAtEcalEntrance = sumEtaTimesEnergy/sumEnergy;
00617
00618 Float_t TauPhi = thePFTau.phi();
00619 Float_t TauPt = thePFTau.pt();
00620 Float_t TauSignalPFChargedCands = thePFTau.signalPFChargedHadrCands().size();
00621 Float_t TauSignalPFGammaCands = thePFTau.signalPFGammaCands().size();
00622 Float_t TauLeadPFChargedHadrHoP = 0.;
00623 Float_t TauLeadPFChargedHadrEoP = 0.;
00624 if ( thePFTau.leadPFChargedHadrCand()->p() > 0. ) {
00625 TauLeadPFChargedHadrHoP = thePFTau.leadPFChargedHadrCand()->hcalEnergy()/thePFTau.leadPFChargedHadrCand()->p();
00626 TauLeadPFChargedHadrEoP = thePFTau.leadPFChargedHadrCand()->ecalEnergy()/thePFTau.leadPFChargedHadrCand()->p();
00627 }
00628 Float_t TauHasGsf = thePFTau.leadPFChargedHadrCand()->gsfTrackRef().isNonnull();
00629 Float_t TauVisMass = thePFTau.mass();
00630 Float_t TauEmFraction = TMath::Max(thePFTau.emFraction(), (Float_t)0.);
00631 std::vector<Float_t> GammasdEta;
00632 std::vector<Float_t> GammasdPhi;
00633 std::vector<Float_t> GammasPt;
00634 for ( unsigned i = 0 ; i < thePFTau.signalPFGammaCands().size(); ++i ) {
00635 reco::PFCandidateRef gamma = thePFTau.signalPFGammaCands().at(i);
00636 if ( thePFTau.leadPFChargedHadrCand().isNonnull() ) {
00637 GammasdEta.push_back(gamma->eta() - thePFTau.leadPFChargedHadrCand()->eta());
00638 GammasdPhi.push_back(gamma->phi() - thePFTau.leadPFChargedHadrCand()->phi());
00639 } else {
00640 GammasdEta.push_back(gamma->eta() - thePFTau.eta());
00641 GammasdPhi.push_back(gamma->phi() - thePFTau.phi());
00642 }
00643 GammasPt.push_back(gamma->pt());
00644 }
00645
00646 Float_t dummyElecEta = 9.9;
00647
00648 return MVAValue(TauEtaAtEcalEntrance,
00649 TauPhi,
00650 TauPt,
00651 TauSignalPFChargedCands,
00652 TauSignalPFGammaCands,
00653 TauLeadPFChargedHadrHoP,
00654 TauLeadPFChargedHadrEoP,
00655 TauHasGsf,
00656 TauVisMass,
00657 TauEmFraction,
00658 GammasdEta,
00659 GammasdPhi,
00660 GammasPt,
00661 dummyElecEta,
00662 0.,
00663 0.,
00664 0.,
00665 0.,
00666 0.,
00667 0.,
00668 0.,
00669 0.,
00670 0.,
00671 0.,
00672 0.,
00673 0.,
00674 0.,
00675 0.,
00676 0.,
00677 0.);
00678 }