CMS 3D CMS Logo

RecoTauPileUpVertexSelector.cc
Go to the documentation of this file.
1 /*
2  * Select reco:Vertices consistent with pileup.
3  *
4  * Author: Evan K. Friis
5  *
6  */
7 
8 
15 
18 
19 #include <functional>
20 #include <algorithm>
21 
22 namespace {
23 
24 class VertexTrackPtSumFilter : public std::unary_function<reco::Vertex, bool> {
25  public:
26  VertexTrackPtSumFilter(double minPt):minPt_(minPt){}
27  bool operator()(const reco::Vertex& vtx) const {
28  double trackPtSum = 0.;
30  track != vtx.tracks_end(); ++track ) {
31  trackPtSum += (*track)->pt();
32  }
33  return trackPtSum > minPt_;
34  }
35  private:
36  double minPt_;
37 };
38 
39 }
40 
42  public:
45  bool filter(edm::Event& evt, const edm::EventSetup& es) override;
46  private:
48  VertexTrackPtSumFilter vtxFilter_;
49  bool filter_;
51 };
52 
54  const edm::ParameterSet& pset):vtxFilter_(
55  pset.getParameter<double>("minTrackSumPt")) {
56  src_ = pset.getParameter<edm::InputTag>("src");
57  token = consumes<reco::VertexCollection>(src_);
58  filter_ = pset.exists("filter") ? pset.getParameter<bool>("filter") : false;
59  produces<reco::VertexCollection>();
60 }
61 
62 
64  edm::Event& evt, const edm::EventSetup& es) {
66  evt.getByToken(token, vertices_);
67  auto output = std::make_unique<reco::VertexCollection>();
68  // If there is only one vertex, there are no PU vertices!
69  if (vertices_->size() > 1) {
70  // Copy over all the vertices that have associatd tracks with pt greater
71  // than the threshold. The predicate function is the VertexTrackPtSumFilter
72  // better name: copy_if_not
73  std::remove_copy_if(vertices_->begin()+1, vertices_->end(),
74  std::back_inserter(*output), std::not1(vtxFilter_));
75  }
76  size_t nPUVtx = output->size();
77  evt.put(std::move(output));
78  // If 'filter' is enabled, return whether true if there are PU vertices
79  if (!filter_)
80  return true;
81  else
82  return nPUVtx;
83 }
84 
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
trackRef_iterator tracks_end() const
last iterator over tracks
Definition: Vertex.cc:81
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
bool exists(std::string const &parameterName) const
checks if a parameter exists
edm::EDGetTokenT< reco::VertexCollection > token
RecoTauPileUpVertexSelector(const edm::ParameterSet &pset)
bool filter(edm::Event &evt, const edm::EventSetup &es) override
std::vector< TrackBaseRef >::const_iterator trackRef_iterator
The iteratator for the vector<TrackRef>
Definition: Vertex.h:37
trackRef_iterator tracks_begin() const
first iterator over tracks
Definition: Vertex.cc:76
def move(src, dest)
Definition: eostools.py:510