CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuonFromPVSelector.cc
Go to the documentation of this file.
1 // Includes
8 
10 
13 
16 
17 #include <memory>
18 #include <vector>
19 #include <sstream>
20 
21 
23 // class definition
26 {
27 public:
28  // construction/destruction
29  MuonFromPVSelector(const edm::ParameterSet& iConfig);
30  virtual ~MuonFromPVSelector();
31 
32  // member functions
33  void produce(edm::Event& iEvent,const edm::EventSetup& iSetup);
34  void endJob();
35 
36 private:
37  // member data
40  double max_dxy_ ;
41  double max_dz_ ;
42 };
43 
44 
45 
47 // construction/destruction
49 
50 //______________________________________________________________________________
52  : srcPart_(iConfig.getParameter<edm::InputTag>("srcMuon"))
53  , srcPV_ (iConfig.getParameter<edm::InputTag>("srcVertex"))
54  , max_dxy_(iConfig.getParameter<double>("max_dxy"))
55  , max_dz_ (iConfig.getParameter<double>("max_dz"))
56 {
57  produces<std::vector<reco::Muon> >();
58 }
59 
60 
61 //______________________________________________________________________________
63 
65 // implementation of member functions
67 
68 //______________________________________________________________________________
70 {
71  std::auto_ptr<std::vector<reco::Muon> > goodMuons(new std::vector<reco::Muon >);
72 
74  iEvent.getByLabel(srcPV_,VertexHandle);
75 
77  iEvent.getByLabel(srcPart_,MuonHandle);
78 
79  if( (VertexHandle->size() == 0) || (MuonHandle->size() == 0) )
80  {
81  iEvent.put(goodMuons);
82  return ;
83  }
84 
85 
86  reco::Vertex PV = VertexHandle->front();
87  //typename std::vector<reco::Muon>::const_iterator MuonIt ;
88  std::vector<reco::Muon>::const_iterator MuonIt ;
89 
90  for (MuonIt = MuonHandle->begin(); MuonIt != MuonHandle->end(); ++MuonIt) {
91  if ( MuonIt->innerTrack().isNonnull() &&
92  fabs(MuonIt->innerTrack()->dxy(PV.position())) < max_dxy_ &&
93  fabs(MuonIt->innerTrack()->dz(PV.position())) < max_dz_ ){
94  goodMuons -> push_back(*MuonIt) ;
95  }
96  }
97 
98  iEvent.put(goodMuons);
99 
100 }
101 
103 {
104 }
105 
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
const Point & position() const
position
Definition: Vertex.h:93
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
MuonFromPVSelector(const edm::ParameterSet &iConfig)
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)