CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuonSelectorVertex.cc
Go to the documentation of this file.
1 //
2 // $Id: MuonSelectorVertex.cc,v 1.1 2012/06/26 16:19:18 vadler Exp $
3 //
4 
5 
9 
10 
12 
13  public:
14 
15  explicit MuonSelectorVertex( const edm::ParameterSet & iConfig );
17  virtual void produce( edm::Event & iEvent, const edm::EventSetup & iSetup );
18 
19  private:
20 
23  double maxDZ_;
24 
25 };
26 
27 
28 #include <vector>
29 #include <memory>
30 #include <cmath>
31 
34 
35 
37 : muonSource_( iConfig.getParameter< edm::InputTag >( "muonSource" ) )
38 , vertexSource_( iConfig.getParameter< edm::InputTag >( "vertexSource" ) )
39 , maxDZ_( iConfig.getParameter< double >( "maxDZ" ) )
40 {
41 
42  produces< std::vector< pat::Muon > >();
43 
44 }
45 
46 
48 {
49 
51  iEvent.getByLabel( muonSource_, muons );
52 
54  iEvent.getByLabel( vertexSource_, vertices );
55 
56  std::vector< pat::Muon > * selectedMuons( new std::vector< pat::Muon > );
57 
58  if ( vertices->size() > 0 ) {
59 
60  for ( unsigned iMuon = 0; iMuon < muons->size(); ++iMuon ) {
61  if ( std::fabs( muons->at( iMuon ).vertex().z() - vertices->at( 0 ).z() ) < maxDZ_ ) {
62  selectedMuons->push_back( muons->at( iMuon ) );
63  }
64  }
65  }
66 
67  std::auto_ptr< std::vector< pat::Muon > > selectedMuonsPtr( selectedMuons );
68  iEvent.put( selectedMuonsPtr );
69 
70 }
71 
72 
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
edm::InputTag muonSource_
edm::InputTag vertexSource_
tuple muons
Definition: patZpeak.py:38
MuonSelectorVertex(const edm::ParameterSet &iConfig)