CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/Validation/RecoTau/plugins/TrackFromPVSelector.cc

Go to the documentation of this file.
00001 
00002 // Includes
00004 #include "FWCore/Framework/interface/EDProducer.h"
00005 #include "FWCore/Framework/interface/Event.h"
00006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00007 #include "FWCore/Utilities/interface/InputTag.h"
00008 
00009 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
00010 
00011 #include "DataFormats/TrackReco/interface/Track.h"
00012 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00013 
00014 #include "DataFormats/VertexReco/interface/Vertex.h"
00015 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00016 
00017 #include <memory>
00018 #include <vector>
00019 #include <sstream>
00020 
00021 
00023 // class definition
00025 class TrackFromPVSelector : public edm::EDProducer
00026 {
00027 public:
00028   // construction/destruction
00029   TrackFromPVSelector(const edm::ParameterSet& iConfig);
00030   virtual ~TrackFromPVSelector();
00031   
00032   // member functions
00033   void produce(edm::Event& iEvent,const edm::EventSetup& iSetup);
00034   void endJob();
00035 
00036 private:  
00037   // member data
00038   edm::InputTag     srcPart_ ;  
00039   edm::InputTag     srcPV_   ;
00040   double            max_dxy_ ;
00041   double            max_dz_  ;
00042 };
00043 
00044 
00045 
00047 // construction/destruction
00049 
00050 //______________________________________________________________________________
00051 TrackFromPVSelector::TrackFromPVSelector(const edm::ParameterSet& iConfig)
00052   : srcPart_(iConfig.getParameter<edm::InputTag>("srcTrack"))
00053   , srcPV_  (iConfig.getParameter<edm::InputTag>("srcVertex"))
00054   , max_dxy_(iConfig.getParameter<double>("max_dxy"))
00055   , max_dz_ (iConfig.getParameter<double>("max_dz"))
00056 {
00057   produces<std::vector<reco::Track> >();
00058 }
00059 
00060 
00061 //______________________________________________________________________________
00062 TrackFromPVSelector::~TrackFromPVSelector(){}
00063 
00065 // implementation of member functions
00067 
00068 //______________________________________________________________________________
00069 void TrackFromPVSelector::produce(edm::Event& iEvent,const edm::EventSetup& iSetup)
00070 {  
00071   std::auto_ptr<std::vector<reco::Track> > goodTracks(new std::vector<reco::Track >);
00072   
00073   edm::Handle< std::vector<reco::Vertex> > VertexHandle;
00074   iEvent.getByLabel(srcPV_,VertexHandle);
00075 
00076   edm::Handle< std::vector<reco::Track> > TrackHandle;
00077   iEvent.getByLabel(srcPart_,TrackHandle);
00078   
00079   if( (VertexHandle->size() == 0) || (TrackHandle->size() == 0) ) 
00080   {
00081     iEvent.put(goodTracks);
00082     return ;
00083   }
00084   
00085   reco::Vertex PV = VertexHandle->front();   
00086   //typename std::vector<reco::Track>::const_iterator TrackIt ;
00087   std::vector<reco::Track>::const_iterator TrackIt ;
00088 
00089   for (TrackIt = TrackHandle->begin(); TrackIt != TrackHandle->end(); ++TrackIt) {
00090     if ( fabs(TrackIt->dxy(PV.position())) < max_dxy_ &&
00091          fabs(TrackIt->dz(PV.position()))  < max_dz_  ){
00092       goodTracks -> push_back(*TrackIt) ;
00093     }
00094   }  
00095   
00096   iEvent.put(goodTracks);
00097   
00098 }
00099 
00100 void TrackFromPVSelector::endJob()
00101 {
00102 }
00103 
00104 #include "FWCore/Framework/interface/MakerMacros.h"
00105 DEFINE_FWK_MODULE(TrackFromPVSelector);