CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/RecoBTag/SoftLepton/plugins/SoftElectronCandProducer.cc

Go to the documentation of this file.
00001 #include "RecoBTag/SoftLepton/plugins/SoftElectronCandProducer.h"
00002 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
00003 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
00004 #include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.h"
00005 #include "DataFormats/Math/interface/deltaR.h"
00006 #include "DataFormats/Math/interface/Vector3D.h"
00007 #include "DataFormats/Math/interface/Point3D.h"
00008 #include "FWCore/Utilities/interface/EDMException.h"
00009 #include "FWCore/Framework/interface/Frameworkfwd.h"
00010 #include "DataFormats/Common/interface/ValueMap.h"
00011 
00012 #include <cmath>
00013 
00014 SoftElectronCandProducer::SoftElectronCandProducer (const edm::ParameterSet& conf) :
00015     gsfElectronTag_                  (conf.getParameter<edm::InputTag>("electrons")),
00016 
00017     barrelPtCuts_                    (conf.getParameter<std::vector<double> >("BarrelPtCuts")),
00018     barreldRGsfTrackElectronCuts_    (conf.getParameter<std::vector<double> >("BarreldRGsfTrackElectronCuts")),
00019     barrelEemPinRatioCuts_           (conf.getParameter<std::vector<double> >("BarrelEemPinRatioCuts")),
00020     barrelMVACuts_                   (conf.getParameter<std::vector<double> >("BarrelMVACuts")),
00021 
00022     forwardPtCuts_                   (conf.getParameter<std::vector<double> >("ForwardPtCuts")),
00023     forwardInverseFBremCuts_         (conf.getParameter<std::vector<double> >("ForwardInverseFBremCuts")),
00024     forwarddRGsfTrackElectronCuts_   (conf.getParameter<std::vector<double> >("ForwarddRGsfTrackElectronCuts")),
00025     forwardMVACuts_                  (conf.getParameter<std::vector<double> >("ForwardMVACuts"))
00026 {
00027     produces< edm::ValueMap<float> >();
00028 }
00029 
00030 SoftElectronCandProducer::~SoftElectronCandProducer()
00031 {
00032 
00033 }
00034 
00035 void SoftElectronCandProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00036 {
00037   edm::Handle<reco::GsfElectronCollection> gsfCandidates;
00038   iEvent.getByLabel(gsfElectronTag_, gsfCandidates);
00039 
00040   std::vector<float> values;
00041   values.reserve(gsfCandidates->size());
00042 
00043   for(reco::GsfElectronCollection::const_iterator iter = gsfCandidates->begin();
00044       iter != gsfCandidates->end(); ++iter)
00045     values.push_back(isClean(*iter) ? 1.0 : 0.0);
00046 
00047   std::auto_ptr< edm::ValueMap<float> > output(new edm::ValueMap<float>);
00048   edm::ValueMap<float>::Filler filler(*output);
00049   filler.insert(gsfCandidates, values.begin(), values.end());
00050   filler.fill();
00051   iEvent.put(output);
00052 }
00053 
00054 bool SoftElectronCandProducer::isClean(const reco::GsfElectron& gsfcandidate)
00055 {
00056   const reco::HitPattern& hitPattern = gsfcandidate.gsfTrack()->hitPattern();
00057   //check that the first hit is a pixel hit
00058   uint32_t hit = hitPattern.getHitPattern(0);
00059   if( !(hitPattern.validHitFilter(hit) && ( (hitPattern.pixelBarrelHitFilter(hit) && hitPattern.getLayer(hit) < 3) || hitPattern.pixelEndcapHitFilter(hit))) )
00060     return false;
00061 
00062   const double EemPinRatio           = (gsfcandidate.eSuperClusterOverP() - 1.0)/(gsfcandidate.eSuperClusterOverP() + 1.0);
00063   const double pt                    = gsfcandidate.pt();
00064   const double fbrem                 = gsfcandidate.fbrem();
00065   const double dRGsfTrackElectron    = deltaR(gsfcandidate.gsfTrack()->eta(), gsfcandidate.gsfTrack()->phi(), gsfcandidate.eta(), gsfcandidate.phi());
00066   const double mva                   = gsfcandidate.mva();
00067 
00068   if(fabs(gsfcandidate.eta()) < 1.5)
00069   {
00070     // use barrel cuts
00071     if( barrelPtCuts_.front()                    > pt                    || barrelPtCuts_.back()                    < pt)                    return false;
00072     if( barreldRGsfTrackElectronCuts_.front()    > dRGsfTrackElectron    || barreldRGsfTrackElectronCuts_.back()    < dRGsfTrackElectron)    return false;
00073     if( barrelEemPinRatioCuts_.front()           > EemPinRatio           || barrelEemPinRatioCuts_.back()           < EemPinRatio)           return false;
00074     if( barrelMVACuts_.front()                   > mva                   || barrelMVACuts_.back()                   < mva)                   return false;
00075   }
00076   else
00077   {
00078     // use endcap cuts
00079     if( forwardPtCuts_.front()                 > pt                 || forwardPtCuts_.back()                 < pt)                 return false;
00080     if( forwardInverseFBremCuts_.front()       > 1.0/fbrem          || forwardInverseFBremCuts_.back()       < 1.0/fbrem)          return false;
00081     if( forwarddRGsfTrackElectronCuts_.front() > dRGsfTrackElectron || forwarddRGsfTrackElectronCuts_.back() < dRGsfTrackElectron) return false;
00082     if( forwardMVACuts_.front()                > mva                || forwardMVACuts_.back()                < mva)                return false;
00083   }
00084 
00085   return true;
00086 }