CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/RecoEgamma/EgammaHLTProducers/src/EgammaHLTElectronDetaDphiProducer.cc

Go to the documentation of this file.
00001 
00009 #include "RecoEgamma/EgammaHLTProducers/interface/EgammaHLTElectronDetaDphiProducer.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 
00022 #include "DataFormats/Common/interface/RefToBase.h"
00023 #include "DataFormats/Common/interface/Ref.h"
00024 #include "DataFormats/Common/interface/RefProd.h"
00025 
00026 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00027 #include "DataFormats/TrackReco/interface/Track.h"
00028 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
00029 
00030 #include "DataFormats/TrackReco/interface/Track.h"
00031 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00032 
00033 #include "CondFormats/DataRecord/interface/BeamSpotObjectsRcd.h"//needed?
00034 #include "CondFormats/BeamSpotObjects/interface/BeamSpotObjects.h"//needed?
00035 
00036 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00037 #include "DataFormats/Math/interface/Point3D.h"
00038 
00039 #include "RecoEgamma/EgammaTools/interface/ECALPositionCalculator.h"
00040 
00041 #include "FWCore/Framework/interface/EventSetup.h"
00042 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00043 #include "MagneticField/Engine/interface/MagneticField.h"
00044 
00045 EgammaHLTElectronDetaDphiProducer::EgammaHLTElectronDetaDphiProducer(const edm::ParameterSet& config) : conf_(config)
00046 {
00047 
00048   electronProducer_             = conf_.getParameter<edm::InputTag>("electronProducer");
00049   BSProducer_                   = conf_.getParameter<edm::InputTag>("BSProducer");
00050   useTrackProjectionToEcal_     = conf_.getUntrackedParameter<bool>("useTrackProjectionToEcal",false);
00051 
00052   //register your products
00053   produces < reco::ElectronIsolationMap >( "Deta" ).setBranchAlias( "deta" );
00054   produces < reco::ElectronIsolationMap >( "Dphi" ).setBranchAlias( "dphi" );
00055 
00056 }
00057 
00058 EgammaHLTElectronDetaDphiProducer::~EgammaHLTElectronDetaDphiProducer(){}
00059 
00060 
00061 //
00062 // member functions
00063 //
00064 
00065 // ------------ method called to produce the data  ------------
00066 void
00067 EgammaHLTElectronDetaDphiProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00068 {
00069 
00070   // Get the HLT filtered objects
00071   edm::Handle<reco::ElectronCollection> electronHandle;
00072   iEvent.getByLabel(electronProducer_,electronHandle);
00073 
00074   edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
00075   iEvent.getByLabel(BSProducer_,recoBeamSpotHandle);
00076   // gets its position
00077   const reco::BeamSpot::Point& BSPosition = recoBeamSpotHandle->position(); 
00078 
00079   edm::ESHandle<MagneticField> theMagField;
00080   iSetup.get<IdealMagneticFieldRecord>().get(theMagField);
00081 
00082   reco::ElectronIsolationMap detaMap;
00083   reco::ElectronIsolationMap dphiMap;
00084 
00085   for(reco::ElectronCollection::const_iterator iElectron = electronHandle->begin(); iElectron != electronHandle->end(); iElectron++){
00086     
00087     reco::ElectronRef eleref(reco::ElectronRef(electronHandle,iElectron - electronHandle->begin()));
00088     const reco::SuperClusterRef theClus = eleref->superCluster();
00089     const math::XYZVector trackMom =  eleref->track()->momentum();
00090     
00091     math::XYZPoint SCcorrPosition(theClus->x()-BSPosition.x(), theClus->y()-BSPosition.y() , theClus->z()-eleref->track()->vz() );
00092     float deltaeta = fabs(SCcorrPosition.eta()-eleref->track()->eta());
00093     float deltaphi;
00094 
00095     if (useTrackProjectionToEcal_) { 
00096 
00097       ECALPositionCalculator posCalc;
00098       const math::XYZPoint vertex(BSPosition.x(),BSPosition.y(),eleref->track()->vz());
00099 
00100       float phi1= posCalc.ecalPhi(theMagField.product(),trackMom,vertex,1);
00101       float phi2= posCalc.ecalPhi(theMagField.product(),trackMom,vertex,-1);
00102 
00103       float deltaphi1=fabs( phi1 - theClus->position().phi() );
00104       if(deltaphi1>6.283185308) deltaphi1 -= 6.283185308;
00105       if(deltaphi1>3.141592654) deltaphi1 = 6.283185308-deltaphi1;
00106 
00107       float deltaphi2=fabs( phi2 - theClus->position().phi() );
00108       if(deltaphi2>6.283185308) deltaphi2 -= 6.283185308;
00109       if(deltaphi2>3.141592654) deltaphi2 = 6.283185308-deltaphi2;
00110 
00111       deltaphi = deltaphi1;
00112       if(deltaphi2<deltaphi1){ deltaphi = deltaphi2;}
00113 
00114     } else {
00115 
00116       deltaphi=fabs(eleref->track()->outerPosition().phi()-theClus->phi());
00117       if(deltaphi>6.283185308) deltaphi -= 6.283185308;
00118       if(deltaphi>3.141592654) deltaphi = 6.283185308-deltaphi;
00119 
00120     }
00121       
00122     detaMap.insert(eleref, deltaeta);
00123     dphiMap.insert(eleref, deltaphi);
00124       
00125   }
00126 
00127   std::auto_ptr<reco::ElectronIsolationMap> detMap(new reco::ElectronIsolationMap(detaMap));
00128   std::auto_ptr<reco::ElectronIsolationMap> dphMap(new reco::ElectronIsolationMap(dphiMap));
00129   iEvent.put(detMap, "Deta" );
00130   iEvent.put(dphMap, "Dphi" );
00131 
00132 }
00133 
00134 //define this as a plug-in
00135 //DEFINE_FWK_MODULE(EgammaHLTTrackIsolationProducers);