CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/RecoEgamma/ElectronIdentification/src/ElectronLikelihood.cc

Go to the documentation of this file.
00001 #include "FWCore/Utilities/interface/Exception.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
00004 #include "RecoEgamma/ElectronIdentification/interface/ElectronLikelihood.h"
00005 #include <iostream>
00006 
00007 
00008 ElectronLikelihood::ElectronLikelihood (const ElectronLikelihoodCalibration *calibration,
00009                                         LikelihoodSwitches eleIDSwitches,
00010                                         std::string signalWeightSplitting,
00011                                         std::string backgroundWeightSplitting,
00012                                         bool splitSignalPdfs,
00013                                         bool splitBackgroundPdfs) :
00014   _EBlt15lh (new LikelihoodPdfProduct ("electronID_EB_ptLt15_likelihood",0,0)) ,
00015   _EElt15lh (new LikelihoodPdfProduct ("electronID_EE_ptLt15_likelihood",1,0)) ,
00016   _EBgt15lh (new LikelihoodPdfProduct ("electronID_EB_ptGt15_likelihood",0,1)) ,
00017   _EEgt15lh (new LikelihoodPdfProduct ("electronID_EE_ptGt15_likelihood",1,1)) ,
00018   m_eleIDSwitches (eleIDSwitches) ,
00019   m_signalWeightSplitting (signalWeightSplitting), 
00020   m_backgroundWeightSplitting (backgroundWeightSplitting),
00021   m_splitSignalPdfs (splitSignalPdfs), 
00022   m_splitBackgroundPdfs (splitBackgroundPdfs)  
00023 {
00024   Setup (calibration,
00025          signalWeightSplitting, backgroundWeightSplitting,
00026          splitSignalPdfs, splitBackgroundPdfs) ;
00027 }
00028 
00029 
00030 
00031 // --------------------------------------------------------
00032 
00033 
00034 
00035 ElectronLikelihood::~ElectronLikelihood () {
00036   delete _EBlt15lh ;
00037   delete _EElt15lh ;
00038   delete _EBgt15lh ;
00039   delete _EEgt15lh ;
00040 }
00041 
00042 
00043 
00044 // --------------------------------------------------------
00045 
00046 
00047 void 
00048 ElectronLikelihood::Setup (const ElectronLikelihoodCalibration *calibration,
00049                            std::string signalWeightSplitting,
00050                            std::string backgroundWeightSplitting,
00051                            bool splitSignalPdfs,
00052                            bool splitBackgroundPdfs) 
00053 {
00054 
00055   // ECAL BARREL LIKELIHOOD - Pt < 15 GeV region
00056   _EBlt15lh->initFromDB (calibration) ;
00057 
00058   _EBlt15lh->addSpecies ("electrons") ;
00059   _EBlt15lh->addSpecies ("hadrons") ;
00060 
00061   if(signalWeightSplitting.compare("class")==0) {
00062     _EBlt15lh->setSplitFrac ("electrons", "class0") ;
00063     _EBlt15lh->setSplitFrac ("electrons", "class1") ;
00064   }
00065   else {
00066     throw cms::Exception("BadConfig") << "Only class (non-showering / showering)"
00067                                       << " and fullclass (golden / bigbrem / narrow / showering)" 
00068                                       << " splitting is implemented right now";
00069   }
00070 
00071   if (m_eleIDSwitches.m_useDeltaPhi)     _EBlt15lh->addPdf ("electrons", "dPhi",          splitSignalPdfs) ;   
00072   if (m_eleIDSwitches.m_useDeltaEta)     _EBlt15lh->addPdf ("electrons", "dEta",          splitSignalPdfs) ;
00073   if (m_eleIDSwitches.m_useEoverP)       _EBlt15lh->addPdf ("electrons", "EoP",           splitSignalPdfs) ;
00074   if (m_eleIDSwitches.m_useHoverE)       _EBlt15lh->addPdf ("electrons", "HoE",           splitSignalPdfs) ;
00075   if (m_eleIDSwitches.m_useSigmaEtaEta)  _EBlt15lh->addPdf ("electrons", "sigmaIEtaIEta", splitSignalPdfs) ;
00076   if (m_eleIDSwitches.m_useSigmaPhiPhi)  _EBlt15lh->addPdf ("electrons", "sigmaIPhiIPhi", splitSignalPdfs) ;
00077   if (m_eleIDSwitches.m_useFBrem)        _EBlt15lh->addPdf ("electrons", "fBrem",         splitSignalPdfs) ;
00078 
00079   if(backgroundWeightSplitting.compare("class")==0) {
00080     _EBlt15lh->setSplitFrac ("hadrons", "class0") ;
00081     _EBlt15lh->setSplitFrac ("hadrons", "class1") ;
00082   }
00083   else {
00084     throw cms::Exception("BadConfig") << "Only class (0 brem clusters / >=1 brem clusters)"
00085                                       << " splitting is implemented right now";
00086   }
00087 
00088   if (m_eleIDSwitches.m_useDeltaPhi)     _EBlt15lh->addPdf ("hadrons", "dPhi",          splitBackgroundPdfs) ;   
00089   if (m_eleIDSwitches.m_useDeltaEta)     _EBlt15lh->addPdf ("hadrons", "dEta",          splitBackgroundPdfs) ;
00090   if (m_eleIDSwitches.m_useEoverP)       _EBlt15lh->addPdf ("hadrons", "EoP",           splitBackgroundPdfs) ;
00091   if (m_eleIDSwitches.m_useHoverE)       _EBlt15lh->addPdf ("hadrons", "HoE",           splitBackgroundPdfs) ;
00092   if (m_eleIDSwitches.m_useSigmaEtaEta)  _EBlt15lh->addPdf ("hadrons", "sigmaIEtaIEta", splitBackgroundPdfs) ;
00093   if (m_eleIDSwitches.m_useSigmaPhiPhi)  _EBlt15lh->addPdf ("hadrons", "sigmaIPhiIPhi", splitBackgroundPdfs) ;
00094   if (m_eleIDSwitches.m_useFBrem)        _EBlt15lh->addPdf ("hadrons", "fBrem",         splitBackgroundPdfs) ;
00095 
00096   // ECAL BARREL LIKELIHOOD - Pt >= 15 GeV region
00097   _EBgt15lh->initFromDB (calibration) ;
00098 
00099   _EBgt15lh->addSpecies ("electrons") ;  
00100   _EBgt15lh->addSpecies ("hadrons") ;
00101 
00102   if(signalWeightSplitting.compare("class")==0) {
00103     _EBgt15lh->setSplitFrac ("electrons", "class0") ;
00104     _EBgt15lh->setSplitFrac ("electrons", "class1") ;
00105   }
00106   else {
00107     throw cms::Exception("BadConfig") << "Only class (0 brem clusters / >=1 brem clusters)"
00108                                       << " splitting is implemented right now";
00109   }
00110 
00111   if (m_eleIDSwitches.m_useDeltaPhi)     _EBgt15lh->addPdf ("electrons", "dPhi",          splitSignalPdfs) ;   
00112   if (m_eleIDSwitches.m_useDeltaEta)     _EBgt15lh->addPdf ("electrons", "dEta",          splitSignalPdfs) ;
00113   if (m_eleIDSwitches.m_useEoverP)       _EBgt15lh->addPdf ("electrons", "EoP",           splitSignalPdfs) ;
00114   if (m_eleIDSwitches.m_useHoverE)       _EBgt15lh->addPdf ("electrons", "HoE",           splitSignalPdfs) ;
00115   if (m_eleIDSwitches.m_useSigmaEtaEta)  _EBgt15lh->addPdf ("electrons", "sigmaIEtaIEta", splitSignalPdfs) ;
00116   if (m_eleIDSwitches.m_useSigmaPhiPhi)  _EBgt15lh->addPdf ("electrons", "sigmaIPhiIPhi", splitSignalPdfs) ;
00117   if (m_eleIDSwitches.m_useFBrem)        _EBgt15lh->addPdf ("electrons", "fBrem",         splitSignalPdfs) ;
00118 
00119   if(backgroundWeightSplitting.compare("class")==0) {
00120     _EBgt15lh->setSplitFrac ("hadrons", "class0") ;
00121     _EBgt15lh->setSplitFrac ("hadrons", "class1") ;
00122   }
00123   else {
00124     throw cms::Exception("BadConfig") << "Only class (0 brem clusters / >=1 brem clusters)"
00125                                       << " splitting is implemented right now";
00126   }
00127 
00128   if (m_eleIDSwitches.m_useDeltaPhi)     _EBgt15lh->addPdf ("hadrons", "dPhi",          splitBackgroundPdfs) ;   
00129   if (m_eleIDSwitches.m_useDeltaEta)     _EBgt15lh->addPdf ("hadrons", "dEta",          splitBackgroundPdfs) ;
00130   if (m_eleIDSwitches.m_useEoverP)       _EBgt15lh->addPdf ("hadrons", "EoP",           splitBackgroundPdfs) ;
00131   if (m_eleIDSwitches.m_useHoverE)       _EBgt15lh->addPdf ("hadrons", "HoE",           splitBackgroundPdfs) ;
00132   if (m_eleIDSwitches.m_useSigmaEtaEta)  _EBgt15lh->addPdf ("hadrons", "sigmaIEtaIEta", splitBackgroundPdfs) ;
00133   if (m_eleIDSwitches.m_useSigmaPhiPhi)  _EBgt15lh->addPdf ("hadrons", "sigmaIPhiIPhi", splitBackgroundPdfs) ;
00134   if (m_eleIDSwitches.m_useFBrem)        _EBgt15lh->addPdf ("hadrons", "fBrem",         splitBackgroundPdfs) ;
00135 
00136   // ECAL ENDCAP LIKELIHOOD - Pt < 15 GeV
00137   _EElt15lh->initFromDB (calibration) ;
00138 
00139   _EElt15lh->addSpecies ("electrons") ;
00140   _EElt15lh->addSpecies ("hadrons") ;
00141 
00142   if(signalWeightSplitting.compare("class")==0) {
00143     _EElt15lh->setSplitFrac ("electrons", "class0") ;
00144     _EElt15lh->setSplitFrac ("electrons", "class1") ;
00145   }
00146   else {
00147     throw cms::Exception("BadConfig") << "Only class (0 brem clusters / >=1 brem clusters)"
00148                                       << " splitting is implemented right now";
00149   }
00150 
00151   if (m_eleIDSwitches.m_useDeltaPhi)     _EElt15lh->addPdf ("electrons", "dPhi",          splitSignalPdfs) ;   
00152   if (m_eleIDSwitches.m_useDeltaEta)     _EElt15lh->addPdf ("electrons", "dEta",          splitSignalPdfs) ;
00153   if (m_eleIDSwitches.m_useEoverP)       _EElt15lh->addPdf ("electrons", "EoP",           splitSignalPdfs) ;
00154   if (m_eleIDSwitches.m_useHoverE)       _EElt15lh->addPdf ("electrons", "HoE",           splitSignalPdfs) ;
00155   if (m_eleIDSwitches.m_useSigmaEtaEta)  _EElt15lh->addPdf ("electrons", "sigmaIEtaIEta", splitSignalPdfs) ;
00156   if (m_eleIDSwitches.m_useSigmaPhiPhi)  _EElt15lh->addPdf ("electrons", "sigmaIPhiIPhi", splitSignalPdfs) ;
00157   if (m_eleIDSwitches.m_useFBrem)        _EElt15lh->addPdf ("electrons", "fBrem",         splitSignalPdfs) ;
00158 
00159   if(backgroundWeightSplitting.compare("class")==0) {
00160     _EElt15lh->setSplitFrac ("hadrons", "class0") ;
00161     _EElt15lh->setSplitFrac ("hadrons", "class1") ;
00162   }
00163   else {
00164     throw cms::Exception("BadConfig") << "Only class (0 brem clusters / >=1 brem clusters)"
00165                                       << " splitting is implemented right now";
00166   }
00167 
00168   if (m_eleIDSwitches.m_useDeltaPhi)     _EElt15lh->addPdf ("hadrons", "dPhi",          splitBackgroundPdfs) ;   
00169   if (m_eleIDSwitches.m_useDeltaEta)     _EElt15lh->addPdf ("hadrons", "dEta",          splitBackgroundPdfs) ;
00170   if (m_eleIDSwitches.m_useEoverP)       _EElt15lh->addPdf ("hadrons", "EoP",           splitBackgroundPdfs) ;
00171   if (m_eleIDSwitches.m_useHoverE)       _EElt15lh->addPdf ("hadrons", "HoE",           splitBackgroundPdfs) ;
00172   if (m_eleIDSwitches.m_useSigmaEtaEta)  _EElt15lh->addPdf ("hadrons", "sigmaIEtaIEta", splitBackgroundPdfs) ;
00173   if (m_eleIDSwitches.m_useSigmaPhiPhi)  _EElt15lh->addPdf ("hadrons", "sigmaIPhiIPhi", splitBackgroundPdfs) ;
00174   if (m_eleIDSwitches.m_useFBrem)        _EElt15lh->addPdf ("hadrons", "fBrem",         splitBackgroundPdfs) ;
00175 
00176   // ECAL ENDCAP LIKELIHOOD - Pt >= 15 GeV
00177   _EEgt15lh->initFromDB (calibration) ;
00178 
00179   _EEgt15lh->addSpecies ("electrons") ;
00180   _EEgt15lh->addSpecies ("hadrons") ;
00181 
00182   if(signalWeightSplitting.compare("class")==0) {
00183     _EEgt15lh->setSplitFrac ("electrons", "class0") ;
00184     _EEgt15lh->setSplitFrac ("electrons", "class1") ;
00185   }
00186   else {
00187     throw cms::Exception("BadConfig") << "Only class (0 brem clusters / >=1 brem clusters)"
00188                                       << " splitting is implemented right now";
00189   }
00190 
00191   if (m_eleIDSwitches.m_useDeltaPhi)     _EEgt15lh->addPdf ("electrons", "dPhi",          splitSignalPdfs) ;   
00192   if (m_eleIDSwitches.m_useDeltaEta)     _EEgt15lh->addPdf ("electrons", "dEta",          splitSignalPdfs) ;
00193   if (m_eleIDSwitches.m_useEoverP)       _EEgt15lh->addPdf ("electrons", "EoP",           splitSignalPdfs) ;
00194   if (m_eleIDSwitches.m_useHoverE)       _EEgt15lh->addPdf ("electrons", "HoE",           splitSignalPdfs) ;
00195   if (m_eleIDSwitches.m_useSigmaEtaEta)  _EEgt15lh->addPdf ("electrons", "sigmaIEtaIEta", splitSignalPdfs) ;
00196   if (m_eleIDSwitches.m_useSigmaPhiPhi)  _EEgt15lh->addPdf ("electrons", "sigmaIPhiIPhi", splitSignalPdfs) ;
00197   if (m_eleIDSwitches.m_useFBrem)        _EEgt15lh->addPdf ("electrons", "fBrem",         splitSignalPdfs) ;
00198 
00199   if(backgroundWeightSplitting.compare("class")==0) {
00200     _EEgt15lh->setSplitFrac ("hadrons", "class0") ;
00201     _EEgt15lh->setSplitFrac ("hadrons", "class1") ;
00202   }
00203   else {
00204     throw cms::Exception("BadConfig") << "Only class (0 brem clusters / >=1 brem clusters)"
00205                                       << " splitting is implemented right now";
00206   }
00207 
00208   if (m_eleIDSwitches.m_useDeltaPhi)     _EEgt15lh->addPdf ("hadrons", "dPhi",          splitBackgroundPdfs) ;   
00209   if (m_eleIDSwitches.m_useDeltaEta)     _EEgt15lh->addPdf ("hadrons", "dEta",          splitBackgroundPdfs) ;
00210   if (m_eleIDSwitches.m_useEoverP)       _EEgt15lh->addPdf ("hadrons", "EoP",           splitBackgroundPdfs) ;
00211   if (m_eleIDSwitches.m_useHoverE)       _EEgt15lh->addPdf ("hadrons", "HoE",           splitBackgroundPdfs) ;
00212   if (m_eleIDSwitches.m_useSigmaEtaEta)  _EEgt15lh->addPdf ("hadrons", "sigmaIEtaIEta", splitBackgroundPdfs) ;
00213   if (m_eleIDSwitches.m_useSigmaPhiPhi)  _EEgt15lh->addPdf ("hadrons", "sigmaIPhiIPhi", splitBackgroundPdfs) ;
00214   if (m_eleIDSwitches.m_useFBrem)        _EEgt15lh->addPdf ("hadrons", "fBrem",         splitBackgroundPdfs) ;
00215 }
00216 
00217 
00218 
00219 // --------------------------------------------------------
00220 
00221 
00222 
00223 void 
00224 ElectronLikelihood::getInputVar (const reco::GsfElectron &electron, 
00225                                  std::vector<float> &measurements, 
00226                                  EcalClusterLazyTools myEcalCluster) const 
00227 {
00228 
00229   // the variables entering the likelihood
00230   if (m_eleIDSwitches.m_useDeltaPhi) measurements.push_back ( electron.deltaPhiSuperClusterTrackAtVtx () ) ;
00231   if (m_eleIDSwitches.m_useDeltaEta) measurements.push_back ( electron.deltaEtaSuperClusterTrackAtVtx () ) ;
00232   if (m_eleIDSwitches.m_useEoverP) measurements.push_back ( electron.eSuperClusterOverP () ) ;
00233   if (m_eleIDSwitches.m_useHoverE) measurements.push_back ( electron.hadronicOverEm () ) ;
00234   std::vector<float> vCov = myEcalCluster.covariances(*(electron.superCluster()->seed())) ;
00235   if (m_eleIDSwitches.m_useSigmaEtaEta) measurements.push_back ( sqrt (vCov[0]) );
00236   if (m_eleIDSwitches.m_useSigmaPhiPhi) measurements.push_back ( sqrt (vCov[2]) );
00237   if(m_eleIDSwitches.m_useFBrem) measurements.push_back( electron.fbrem() );
00238 
00239 }
00240 
00241 
00242 
00243 // --------------------------------------------------------
00244 
00245 
00246 
00247 float 
00248 ElectronLikelihood::result (const reco::GsfElectron &electron, 
00249                             EcalClusterLazyTools myEcalCluster) const 
00250 {
00251 
00252   //=======================================================
00253   // used classification:
00254   // nbrem clusters = 0         =>  0
00255   // nbrem clusters >= 1        =>  1
00256   //=======================================================
00257 
00258   std::vector<float> measurements ;
00259   getInputVar (electron, measurements, myEcalCluster) ;
00260 
00261   // Split using only the number of brem clusters
00262   int bitVal=(electron.numberOfBrems()==0) ? 0 : 1 ;
00263   
00264   char className[20] ;
00265   if(m_signalWeightSplitting.compare("class")==0) {
00266     sprintf (className,"class%d",bitVal);
00267   } else {
00268     throw cms::Exception("BadConfig") << "Only class (0 brem clusters / >=1 brem clusters)"
00269                                       << " splitting is implemented right now";
00270   }
00271 
00272   reco::SuperClusterRef sclusRef = electron.superCluster() ;
00273   EcalSubdetector subdet = EcalSubdetector (sclusRef->hitsAndFractions()[0].first.subdetId ()) ;
00274   float thisPt =  electron.pt();
00275 
00276   if (subdet==EcalBarrel && thisPt<15.)
00277     return _EBlt15lh->getRatio ("electrons",measurements,std::string (className)) ;
00278   else if (subdet==EcalBarrel && thisPt>=15.)
00279     return _EBgt15lh->getRatio ("electrons",measurements,std::string (className)) ;
00280   else if (subdet==EcalEndcap && thisPt<15.)
00281     return _EElt15lh->getRatio ("electrons",measurements,std::string (className)) ;
00282   else if (subdet==EcalEndcap && thisPt>=15.)
00283     return _EEgt15lh->getRatio ("electrons",measurements,std::string (className)) ;
00284   else return -999. ;
00285 }
00286