CMS 3D CMS Logo

TrackFromPVSelector.cc
Go to the documentation of this file.
1 // Includes
9 
11 
16 
17 #include <algorithm>
18 #include <numeric>
19 #include <memory>
20 #include <vector>
21 
23 // class definition
26 public:
27  explicit TrackFromPVSelector(edm::ParameterSet const& iConfig);
28 
29  void produce(edm::StreamID, edm::Event& iEvent, edm::EventSetup const& iSetup) const override;
30 
31 private:
32  double max_dxy_;
33  double max_dz_;
36 };
37 
39 // construction/destruction
41 
42 //______________________________________________________________________________
44  : max_dxy_{iConfig.getParameter<double>("max_dxy")},
45  max_dz_{iConfig.getParameter<double>("max_dz")},
46  v_recoVertexToken_{consumes<std::vector<reco::Vertex>>(iConfig.getParameter<edm::InputTag>("srcVertex"))},
47  v_recoTrackToken_{consumes<std::vector<reco::Track>>(iConfig.getParameter<edm::InputTag>("srcTrack"))} {
48  produces<std::vector<reco::Track>>();
49 }
50 
52 // implementation of member functions
54 
55 //______________________________________________________________________________
58  iEvent.getByToken(v_recoVertexToken_, vertices);
59 
61  iEvent.getByToken(v_recoTrackToken_, tracks);
62 
63  auto goodTracks = std::make_unique<std::vector<reco::Track>>();
64  if (!vertices->empty() && !tracks->empty()) {
65  auto const& vtxPos = vertices->front().position();
66  std::copy_if(
67  std::cbegin(*tracks), std::cend(*tracks), std::back_inserter(*goodTracks), [this, &vtxPos](auto const& track) {
68  return std::abs(track.dxy(vtxPos)) < max_dxy_ && std::abs(track.dz(vtxPos)) < max_dz_;
69  });
70  }
72 }
73 
edm::EDGetTokenT< std::vector< reco::Vertex > > v_recoVertexToken_
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
edm::EDGetTokenT< std::vector< reco::Track > > v_recoTrackToken_
TrackFromPVSelector(edm::ParameterSet const &iConfig)
int iEvent
Definition: GenABIO.cc:224
void produce(edm::StreamID, edm::Event &iEvent, edm::EventSetup const &iSetup) const override
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
def move(src, dest)
Definition: eostools.py:511