CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
14 
17 
18 #include <functional>
19 #include <algorithm>
20 
21 namespace {
22 
23 class VertexTrackPtSumFilter : public std::unary_function<reco::Vertex, bool> {
24  public:
25  VertexTrackPtSumFilter(double minPt):minPt_(minPt){}
26  bool operator()(const reco::Vertex& vtx) const {
27  double trackPtSum = 0.;
29  track != vtx.tracks_end(); ++track ) {
30  trackPtSum += (*track)->pt();
31  }
32  return trackPtSum > minPt_;
33  }
34  private:
35  double minPt_;
36 };
37 
38 }
39 
41  public:
42  explicit RecoTauPileUpVertexSelector(const edm::ParameterSet &pset);
44  bool filter(edm::Event& evt, const edm::EventSetup& es);
45  private:
47  VertexTrackPtSumFilter vtxFilter_;
48  bool filter_;
49 };
50 
52  const edm::ParameterSet& pset):vtxFilter_(
53  pset.getParameter<double>("minTrackSumPt")) {
54  src_ = pset.getParameter<edm::InputTag>("src");
55  filter_ = pset.exists("filter") ? pset.getParameter<bool>("filter") : false;
56  produces<reco::VertexCollection>();
57 }
58 
59 
61  edm::Event& evt, const edm::EventSetup& es) {
63  evt.getByLabel(src_, vertices_);
64  std::auto_ptr<reco::VertexCollection> output(new reco::VertexCollection);
65  // If there is only one vertex, there are no PU vertices!
66  if (vertices_->size() > 1) {
67  // Copy over all the vertices that have associatd tracks with pt greater
68  // than the threshold. The predicate function is the VertexTrackPtSumFilter
69  // better name: copy_if_not
70  std::remove_copy_if(vertices_->begin()+1, vertices_->end(),
71  std::back_inserter(*output), std::not1(vtxFilter_));
72  }
73  size_t nPUVtx = output->size();
74  evt.put(output);
75  // If 'filter' is enabled, return whether true if there are PU vertices
76  if (!filter_)
77  return true;
78  else
79  return nPUVtx;
80 }
81 
T getParameter(std::string const &) const
trackRef_iterator tracks_end() const
last iterator over tracks
Definition: Vertex.cc:45
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
RecoTauPileUpVertexSelector(const edm::ParameterSet &pset)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
std::vector< TrackBaseRef >::const_iterator trackRef_iterator
The iteratator for the vector&lt;TrackRef&gt;
Definition: Vertex.h:38
trackRef_iterator tracks_begin() const
first iterator over tracks
Definition: Vertex.cc:40
bool filter(edm::Event &evt, const edm::EventSetup &es)