CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch2/src/Validation/RecoTau/plugins/MuonFromPVSelector.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/MuonReco/interface/Muon.h"
00012 #include "DataFormats/MuonReco/interface/MuonFwd.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 MuonFromPVSelector : public edm::EDProducer
00026 {
00027 public:
00028   // construction/destruction
00029   MuonFromPVSelector(const edm::ParameterSet& iConfig);
00030   virtual ~MuonFromPVSelector();
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 MuonFromPVSelector::MuonFromPVSelector(const edm::ParameterSet& iConfig)
00052   : srcPart_(iConfig.getParameter<edm::InputTag>("srcMuon"))
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::Muon> >();
00058 }
00059 
00060 
00061 //______________________________________________________________________________
00062 MuonFromPVSelector::~MuonFromPVSelector(){}
00063 
00065 // implementation of member functions
00067 
00068 //______________________________________________________________________________
00069 void MuonFromPVSelector::produce(edm::Event& iEvent,const edm::EventSetup& iSetup)
00070 {  
00071   std::auto_ptr<std::vector<reco::Muon> > goodMuons(new std::vector<reco::Muon >);
00072   
00073   edm::Handle< std::vector<reco::Vertex> > VertexHandle;
00074   iEvent.getByLabel(srcPV_,VertexHandle);
00075 
00076   edm::Handle< std::vector<reco::Muon> > MuonHandle;
00077   iEvent.getByLabel(srcPart_,MuonHandle);
00078   
00079   if( (VertexHandle->size() == 0) || (MuonHandle->size() == 0) ) 
00080   {
00081     iEvent.put(goodMuons);
00082     return ;
00083   }
00084   
00085   
00086   reco::Vertex PV = VertexHandle->front();   
00087   //typename std::vector<reco::Muon>::const_iterator MuonIt ;
00088   std::vector<reco::Muon>::const_iterator MuonIt ;
00089 
00090   for (MuonIt = MuonHandle->begin(); MuonIt != MuonHandle->end(); ++MuonIt) {
00091     if ( MuonIt->innerTrack().isNonnull()                          &&
00092          fabs(MuonIt->innerTrack()->dxy(PV.position())) < max_dxy_ &&
00093          fabs(MuonIt->innerTrack()->dz(PV.position()))  < max_dz_  ){
00094       goodMuons -> push_back(*MuonIt) ;
00095     }
00096   }  
00097   
00098   iEvent.put(goodMuons);
00099   
00100 }
00101 
00102 void MuonFromPVSelector::endJob()
00103 {
00104 }
00105 
00106 #include "FWCore/Framework/interface/MakerMacros.h"
00107 DEFINE_FWK_MODULE(MuonFromPVSelector);