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 //
3 
4 
8 
11 
12 
14 
15  public:
16 
17  explicit MuonSelectorVertex( const edm::ParameterSet & iConfig );
19  virtual void produce( edm::Event & iEvent, const edm::EventSetup & iSetup ) override;
20 
21  private:
22 
25  double maxDZ_;
26 
27 };
28 
29 
30 #include <vector>
31 #include <memory>
32 #include <cmath>
33 
34 
36 : muonSource_( consumes< std::vector< pat::Muon > >( iConfig.getParameter< edm::InputTag >( "muonSource" ) ) )
37 , vertexSource_( consumes< std::vector< reco::Vertex > >( iConfig.getParameter< edm::InputTag >( "vertexSource" ) ) )
38 , maxDZ_( iConfig.getParameter< double >( "maxDZ" ) )
39 {
40 
41  produces< std::vector< pat::Muon > >();
42 
43 }
44 
45 
47 {
48 
50  iEvent.getByToken( muonSource_, muons );
51 
53  iEvent.getByToken( vertexSource_, vertices );
54 
55  std::vector< pat::Muon > * selectedMuons( new std::vector< pat::Muon > );
56 
57  if ( vertices->size() > 0 ) {
58 
59  for ( unsigned iMuon = 0; iMuon < muons->size(); ++iMuon ) {
60  if ( std::fabs( muons->at( iMuon ).vertex().z() - vertices->at( 0 ).z() ) < maxDZ_ ) {
61  selectedMuons->push_back( muons->at( iMuon ) );
62  }
63  }
64  }
65 
66  std::auto_ptr< std::vector< pat::Muon > > selectedMuonsPtr( selectedMuons );
67  iEvent.put( selectedMuonsPtr );
68 
69 }
70 
71 
edm::EDGetTokenT< std::vector< pat::Muon > > muonSource_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
int iEvent
Definition: GenABIO.cc:230
edm::EDGetTokenT< std::vector< reco::Vertex > > vertexSource_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
tuple muons
Definition: patZpeak.py:38
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
MuonSelectorVertex(const edm::ParameterSet &iConfig)