CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/RecoEgamma/EgammaHLTProducers/src/EgammaHLTElectronTrackIsolationProducers.cc

Go to the documentation of this file.
00001 
00009 #include "RecoEgamma/EgammaHLTProducers/interface/EgammaHLTElectronTrackIsolationProducers.h"
00010 
00011 // Framework
00012 #include "FWCore/Framework/interface/Event.h"
00013 #include "FWCore/Framework/interface/EventSetup.h"
00014 #include "DataFormats/Common/interface/Handle.h"
00015 #include "FWCore/Framework/interface/ESHandle.h"
00016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00017 #include "FWCore/Utilities/interface/Exception.h"
00018 
00019 #include "DataFormats/EgammaCandidates/interface/Electron.h"
00020 #include "DataFormats/EgammaCandidates/interface/ElectronIsolationAssociation.h"
00021 #include "DataFormats/RecoCandidate/interface/RecoEcalCandidate.h"
00022 #include "DataFormats/RecoCandidate/interface/RecoEcalCandidateIsolation.h"
00023 #include "DataFormats/Common/interface/RefToBase.h"
00024 #include "DataFormats/Common/interface/Ref.h"
00025 #include "DataFormats/Common/interface/RefProd.h"
00026 
00027 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00028 #include "DataFormats/TrackReco/interface/Track.h"
00029 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
00030 
00031 
00032 #include "RecoEgamma/EgammaIsolationAlgos/interface/ElectronTkIsolation.h"
00033 
00034 EgammaHLTElectronTrackIsolationProducers::EgammaHLTElectronTrackIsolationProducers(const edm::ParameterSet& config)
00035 {
00036 
00037   electronProducer_             = config.getParameter<edm::InputTag>("electronProducer");
00038   trackProducer_                = config.getParameter<edm::InputTag>("trackProducer");
00039   recoEcalCandidateProducer_ = config.getParameter<edm::InputTag>("recoEcalCandidateProducer"); 
00040   beamSpotProducer_ = config.getParameter<edm::InputTag>("beamSpotProducer");
00041 
00042   useGsfTrack_ = config.getParameter<bool>("useGsfTrack");
00043   useSCRefs_ = config.getParameter<bool>("useSCRefs");
00044   
00045   egTrkIsoPtMin_                = config.getParameter<double>("egTrkIsoPtMin");
00046   egTrkIsoConeSize_             = config.getParameter<double>("egTrkIsoConeSize");
00047   egTrkIsoZSpan_                = config.getParameter<double>("egTrkIsoZSpan");
00048   egTrkIsoRSpan_                = config.getParameter<double>("egTrkIsoRSpan");
00049   egTrkIsoVetoConeSizeBarrel_         = config.getParameter<double>("egTrkIsoVetoConeSizeBarrel");
00050   egTrkIsoVetoConeSizeEndcap_         = config.getParameter<double>("egTrkIsoVetoConeSizeEndcap");
00051   // egCheckForOtherEleInCone_     = config.getUntrackedParameter<bool>("egCheckForOtherEleInCone",false);
00052   egTrkIsoStripBarrel_   = config.getParameter<double>("egTrkIsoStripBarrel");
00053   egTrkIsoStripEndcap_   = config.getParameter<double>("egTrkIsoStripEndcap");
00054 
00055  
00056 
00057 
00058   //register your products
00059   if(useSCRefs_) produces < reco::RecoEcalCandidateIsolationMap >();
00060   else produces < reco::ElectronIsolationMap >();
00061 }
00062 
00063 
00064 EgammaHLTElectronTrackIsolationProducers::~EgammaHLTElectronTrackIsolationProducers(){}
00065 
00066 
00067 //
00068 // member functions
00069 //
00070 
00071 // ------------ method called to produce the data  ------------
00072 void
00073 EgammaHLTElectronTrackIsolationProducers::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00074 {
00075 
00076   edm::Handle<reco::ElectronCollection> electronHandle;
00077   iEvent.getByLabel(electronProducer_,electronHandle);
00078 
00079 
00080  // Get the general tracks
00081   edm::Handle<reco::TrackCollection> trackHandle;
00082   iEvent.getByLabel(trackProducer_, trackHandle);
00083   const reco::TrackCollection* trackCollection = trackHandle.product();
00084 
00085   reco::ElectronIsolationMap eleMap;
00086   reco::RecoEcalCandidateIsolationMap recoEcalCandMap;
00087 
00088   edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
00089   iEvent.getByLabel(beamSpotProducer_,recoBeamSpotHandle);
00090   
00091   const reco::BeamSpot::Point& beamSpotPosition = recoBeamSpotHandle->position(); 
00092 
00093   ElectronTkIsolation isoAlgo(egTrkIsoConeSize_,egTrkIsoVetoConeSizeBarrel_,egTrkIsoVetoConeSizeEndcap_,egTrkIsoStripBarrel_,egTrkIsoStripEndcap_,egTrkIsoPtMin_, egTrkIsoZSpan_ ,egTrkIsoRSpan_,trackCollection,beamSpotPosition);
00094   
00095   if(useSCRefs_){
00096     edm::Handle<reco::RecoEcalCandidateCollection> recoEcalCandHandle;
00097     iEvent.getByLabel(recoEcalCandidateProducer_,recoEcalCandHandle);
00098     for(reco::RecoEcalCandidateCollection::const_iterator iRecoEcalCand = recoEcalCandHandle->begin(); iRecoEcalCand != recoEcalCandHandle->end(); iRecoEcalCand++){
00099       
00100       reco::RecoEcalCandidateRef recoEcalCandRef(recoEcalCandHandle,iRecoEcalCand-recoEcalCandHandle->begin());
00101       
00102       reco::ElectronRef eleRef;
00103       for(reco::ElectronCollection::const_iterator eleIt = electronHandle->begin(); eleIt != electronHandle->end(); eleIt++){
00104         if(eleIt->superCluster()==recoEcalCandRef->superCluster()){
00105           eleRef = reco::ElectronRef(electronHandle,eleIt - electronHandle->begin());
00106           break;
00107       }
00108       }
00109       float isol=999999;
00110       if(eleRef.isNonnull()){
00111         const reco::Track* eleTrk = useGsfTrack_ ? &*eleRef->gsfTrack() : &*eleRef->track();
00112         isol = isoAlgo.getIso(eleTrk).second;
00113       }
00114       recoEcalCandMap.insert(recoEcalCandRef,isol);
00115     }//end reco ecal candidate ref
00116   }else{ //we are going to loop over electron instead
00117     for(reco::ElectronCollection::const_iterator iElectron = electronHandle->begin(); iElectron != electronHandle->end(); iElectron++){
00118       reco::ElectronRef eleRef(reco::ElectronRef(electronHandle,iElectron - electronHandle->begin()));
00119       const reco::Track* eleTrk = useGsfTrack_ ? &*eleRef->gsfTrack() : &*eleRef->track();
00120       float isol = isoAlgo.getIso(eleTrk).second;
00121       eleMap.insert(eleRef, isol);
00122     }
00123   }
00124 
00125   if(useSCRefs_){
00126     std::auto_ptr<reco::RecoEcalCandidateIsolationMap> mapForEvent(new reco::RecoEcalCandidateIsolationMap(recoEcalCandMap));
00127     iEvent.put(mapForEvent);
00128   }else{
00129     std::auto_ptr<reco::ElectronIsolationMap> mapForEvent(new reco::ElectronIsolationMap(eleMap));
00130     iEvent.put(mapForEvent);
00131   }
00132   
00133 
00134 }
00135 
00136 //define this as a plug-in
00137 //DEFINE_FWK_MODULE(EgammaHLTTrackIsolationProducers);