CMS 3D CMS Logo

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 );
18  ~ MuonSelectorVertex() override {};
19  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->empty() ) {
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::unique_ptr< std::vector< pat::Muon > > selectedMuonsPtr( selectedMuons );
67  iEvent.put(std::move(selectedMuonsPtr));
68 
69 }
70 
71 
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
edm::EDGetTokenT< std::vector< pat::Muon > > muonSource_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
selectedMuons
====================================== Muons
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: HeavyIon.h:7
int iEvent
Definition: GenABIO.cc:230
edm::EDGetTokenT< std::vector< reco::Vertex > > vertexSource_
Definition: Muon.py:1
~MuonSelectorVertex() override
fixed size matrix
HLT enums.
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
MuonSelectorVertex(const edm::ParameterSet &iConfig)
def move(src, dest)
Definition: eostools.py:510