CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/RecoEgamma/EgammaHLTAlgos/src/EgammaHLTPixelMatchElectronAlgo.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    EgammaHLTAlgos
00004 // Class:      EgammaHLTPixelMatchElectronAlgo.
00005 // 
00011 //
00012 // Original Author:  Monica Vazquez Acosta (CERN)
00013 // $Id: EgammaHLTPixelMatchElectronAlgo.cc,v 1.14 2009/10/14 14:18:31 covarell Exp $
00014 //
00015 //
00016 #include "RecoEgamma/EgammaHLTAlgos/interface/EgammaHLTPixelMatchElectronAlgo.h"
00017 
00018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00019 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00020 
00021 #include "TrackingTools/PatternTools/interface/TSCPBuilderNoMaterial.h"
00022 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
00023 #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
00024 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateClosestToPoint.h"
00025 
00026 #include "RecoTracker/Record/interface/TrackerRecoGeometryRecord.h"
00027 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00028 
00029 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00030 #include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
00031 #include "DataFormats/EgammaReco/interface/ElectronSeed.h"
00032 #include "DataFormats/EgammaReco/interface/ElectronSeedFwd.h"
00033 
00034 #include "DataFormats/TrackCandidate/interface/TrackCandidate.h"
00035 #include "DataFormats/TrackCandidate/interface/TrackCandidateCollection.h"
00036 
00037 #include "DataFormats/TrackReco/interface/Track.h"
00038 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00039 
00040 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00041 #include "DataFormats/Math/interface/Point3D.h"
00042 
00043 using namespace edm;
00044 using namespace std;
00045 using namespace reco;
00046 //using namespace math; // conflicts with DataFormat/Math/interface/Point3D.h!!!!
00047 
00048 //EgammaHLTPixelMatchElectronAlgo::EgammaHLTPixelMatchElectronAlgo():  
00049 //  theCkfTrajectoryBuilder(0), theTrajectoryCleaner(0),
00050 //  theInitialStateEstimator(0), theNavigationSchool(0) {}
00051 
00052 EgammaHLTPixelMatchElectronAlgo::EgammaHLTPixelMatchElectronAlgo(const edm::ParameterSet &conf) :
00053   trackProducer_( conf.getParameter<edm::InputTag>("TrackProducer") ),
00054   BSProducer_(    conf.getParameter<edm::InputTag>("BSProducer") )
00055 {}
00056 
00057 EgammaHLTPixelMatchElectronAlgo::~EgammaHLTPixelMatchElectronAlgo() {
00058 
00059   // delete theInitialStateEstimator;
00060   //delete theNavigationSchool;
00061   //delete theTrajectoryCleaner; 
00062     
00063 }
00064 
00065 void EgammaHLTPixelMatchElectronAlgo::setupES(const edm::EventSetup& es) {
00066   //services
00067   es.get<TrackerRecoGeometryRecord>().get(theGeomSearchTracker);
00068   es.get<IdealMagneticFieldRecord>().get(theMagField);
00069 }
00070 
00071 void  EgammaHLTPixelMatchElectronAlgo::run(Event& e, ElectronCollection & outEle) {
00072 
00073   // get the input 
00074   edm::Handle<TrackCollection> tracksH;
00075   //  e.getByLabel(trackLabel_,trackInstanceName_,tracksH);
00076  e.getByLabel(trackProducer_,tracksH);
00077 
00078   //Get the Beam Spot position
00079   edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
00080   // iEvent.getByType(recoBeamSpotHandle);
00081   e.getByLabel(BSProducer_,recoBeamSpotHandle);
00082   // gets its position
00083   const BeamSpot::Point& BSPosition = recoBeamSpotHandle->position(); 
00084   Global3DPoint bs(BSPosition.x(),BSPosition.y(),0);
00085   process(tracksH,outEle,bs);
00086 
00087   return;
00088 }
00089 
00090 void EgammaHLTPixelMatchElectronAlgo::process(edm::Handle<TrackCollection> tracksH, ElectronCollection & outEle, Global3DPoint & bs) {
00091   const TrackCollection *tracks=tracksH.product();
00092   for (unsigned int i=0;i<tracks->size();++i) {
00093     const Track & t=(*tracks)[i];
00094 
00095     const TrackRef trackRef = edm::Ref<TrackCollection>(tracksH,i);
00096     edm::RefToBase<TrajectorySeed> seed = trackRef->extra()->seedRef();
00097     ElectronSeedRef elseed=seed.castTo<ElectronSeedRef>();
00098 
00099     edm::RefToBase<CaloCluster> caloCluster = elseed->caloCluster() ;
00100     SuperClusterRef scRef = caloCluster.castTo<SuperClusterRef>() ;
00101 
00102     //const SuperClusterRef & scRef=elseed->superCluster();
00103     
00104         // Get the momentum at vertex (not at the innermost layer)
00105     TSCPBuilderNoMaterial tscpBuilder;
00106     TrajectoryStateTransform tsTransform;
00107     FreeTrajectoryState fts = tsTransform.innerFreeState(t,theMagField.product());
00108     TrajectoryStateClosestToPoint tscp = tscpBuilder(fts, bs );
00109     
00110     float scale = scRef->energy()/tscp.momentum().mag();
00111   
00112     const math::XYZTLorentzVector momentum(tscp.momentum().x()*scale,
00113                                            tscp.momentum().y()*scale,
00114                                            tscp.momentum().z()*scale,
00115                                            scRef->energy());
00116 
00117     
00118     Electron ele(t.charge(),momentum, t.vertex() );
00119     ele.setSuperCluster(scRef);
00120     edm::Ref<TrackCollection> myRef(tracksH,i);
00121     ele.setTrack(myRef);
00122     outEle.push_back(ele);
00123 
00124   }  // loop over tracks
00125 }
00126