CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/PhysicsTools/PatUtils/src/ElectronSelector.cc

Go to the documentation of this file.
00001 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
00002 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
00003 #include "DataFormats/EgammaReco/interface/ClusterShape.h"
00004 
00005 #include "PhysicsTools/PatUtils/interface/ElectronSelector.h"
00006 
00007 using pat::ElectronSelector;
00008 
00009 //______________________________________________________________________________
00010 const pat::ParticleStatus
00011 ElectronSelector::filter( const unsigned int&        index, 
00012                           const edm::View<Electron>& electrons,
00013                           const ElectronIDmap&       electronIDs,
00014                           const reco::ClusterShape*  clusterShape 
00015                           ) const
00016 {
00017 
00018   // List of possible selections
00019   if      ( config_.selectionType == "none"       ) 
00020     {
00021       return GOOD;
00022     }
00023   else if ( config_.selectionType == "cut"        ) 
00024     {
00025       if ( electronID_(index,electrons,electronIDs)->cutBasedDecision() ) return GOOD;
00026       return BAD;
00027     }
00028   else if ( config_.selectionType == "likelihood" )
00029     {
00030       if ( electronID_(index,electrons,electronIDs)->likelihood() > config_.value ) return GOOD;
00031       return BAD;
00032     }
00033   else if ( config_.selectionType == "neuralnet" ) // FIXME: Check sign of comparison!
00034     {
00035       if ( electronID_(index,electrons,electronIDs)->neuralNetOutput() > config_.value ) return GOOD;
00036       return BAD;
00037     }
00038   else if ( config_.selectionType == "custom"     ) 
00039     {
00040       return customSelection_( index, electrons, clusterShape );
00041     }
00042 
00043 
00044   // Throw! unknown configuration
00045   throw edm::Exception(edm::errors::Configuration) 
00046     << "Unknown electron ID selection " << config_.selectionType;
00047 
00048 }
00049 
00050 
00051 //______________________________________________________________________________
00052 const reco::ElectronIDRef& 
00053 ElectronSelector::electronID_( const unsigned int& index,
00054                                const edm::View<Electron>& electrons,
00055                                const ElectronIDmap& electronIDs
00056                                ) const
00057 {
00058   // Find electron ID for electron with index index
00059   edm::Ref<std::vector<Electron> > elecsRef = electrons.refAt(index).castTo<edm::Ref<std::vector<Electron> > >();
00060   ElectronIDmap::const_iterator electronID = electronIDs.find( elecsRef );
00061 
00062   // Return corresponding elecID
00063   return electronID->val;
00064 }
00065 
00066 
00067 //______________________________________________________________________________
00068 const pat::ParticleStatus
00069 ElectronSelector::customSelection_( const unsigned int&        index,
00070                                     const edm::View<Electron>& electrons,
00071                                     const reco::ClusterShape*  clusterShape
00072                                     ) const
00073 {
00074 
00075   // Note: this is all taken from SusyAnalyzer
00076 
00077   const reco::GsfElectron& electron = electrons[index];
00078 
00079   // Retrieve information
00080   float eta          = fabs(electron.p4().Eta());
00081   float eOverPin     = electron.eSuperClusterOverP();
00082   float pin          = electron.trackMomentumAtVtx().R();   
00083   float pout         = electron.trackMomentumOut().R(); 
00084   float fBrem        = (pin-pout)/pin;
00085   float hOverE       = electron.hadronicOverEm();
00086   float deltaPhiIn   = electron.deltaPhiSuperClusterTrackAtVtx();
00087   float deltaEtaIn   = electron.deltaEtaSuperClusterTrackAtVtx();
00088   float deltaPhiOut  = electron.deltaPhiSeedClusterTrackAtCalo();
00089   float invEOverInvP = (1./electron.caloEnergy())-(1./electron.trackMomentumAtVtx().R());
00090   float sigmaee      = sqrt(clusterShape->covEtaEta());
00091   float sigmapp      = sqrt(clusterShape->covPhiPhi());
00092   float E9overE25    = clusterShape->e3x3()/clusterShape->e5x5();
00093 
00094   bool inEndCap = false; // Switch between barrel (0) and endcap (2)
00095   if (eta > 1.479) { // See EgammaAnalysis/ElectronIDAlgos/src/CutBasedElectronID.cc
00096     inEndCap = true; 
00097     sigmaee = sigmaee - 0.02*(fabs(eta) - 2.3);   // Correct sigmaetaeta dependence on eta in endcap
00098   }
00099 
00100   // Now do the selection
00101   // These ones come straight from E/gamma algo
00102   if ( (eOverPin < 0.8) && (fBrem < 0.2) ) return BAD;
00103   if ( config_.doBremEoverPcomp && (eOverPin < 0.9*(1-fBrem)) ) return BAD;
00104 
00105   if (  (hOverE > config_.HoverEBarmax       && !inEndCap )
00106      || (hOverE > config_.HoverEEndmax       &&  inEndCap ) )
00107     return HOVERE;
00108 
00109   if (  (E9overE25 < config_.E9overE25Barmin && !inEndCap )
00110      || (E9overE25 < config_.E9overE25Endmin &&  inEndCap ) )
00111     return SHOWER;
00112 
00113   if (  (sigmaee > config_.SigmaEtaEtaBarmax && !inEndCap )
00114      || (sigmaee > config_.SigmaEtaEtaEndmax &&  inEndCap ) )
00115     return SHOWER;
00116 
00117   if (  (sigmapp > config_.SigmaPhiPhiBarmax && !inEndCap )
00118      || (sigmapp > config_.SigmaPhiPhiEndmax &&  inEndCap ) )
00119     return SHOWER;
00120 
00121   if (  (eOverPin < config_.EoverPInBarmin   && !inEndCap )
00122      || (eOverPin < config_.EoverPInEndmin   &&  inEndCap ) )
00123     return MATCHING;
00124 
00125   if (  (fabs(deltaEtaIn) > config_.DeltaEtaInBarmax   && !inEndCap )
00126      || (fabs(deltaEtaIn) > config_.DeltaEtaInEndmax   &&  inEndCap ) )
00127     return MATCHING;
00128 
00129   if (  (fabs(deltaPhiIn) < config_.DeltaPhiInBarmax   && !inEndCap )
00130      || (fabs(deltaPhiIn) < config_.DeltaPhiInEndmax   &&  inEndCap ) )
00131     return MATCHING;
00132 
00133   if (  (fabs(deltaPhiOut) < config_.DeltaPhiOutBarmax && !inEndCap )
00134      || (fabs(deltaPhiOut) < config_.DeltaPhiOutEndmax &&  inEndCap ) )
00135     return MATCHING;
00136 
00137   if (  (invEOverInvP > config_.InvEMinusInvPBarmax && !inEndCap )
00138      || (invEOverInvP > config_.InvEMinusInvPEndmax &&  inEndCap ) )
00139     return MATCHING;
00140    
00141   return GOOD;
00142 
00143 }