CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoTauTag/RecoTau/plugins/RecoTauPileUpVertexSelector.cc

Go to the documentation of this file.
00001 /*
00002  * Select reco:Vertices consistent with pileup.
00003  *
00004  * Author: Evan K. Friis
00005  *
00006  */
00007 
00008 
00009 #include "FWCore/Framework/interface/EDFilter.h"
00010 #include "FWCore/Framework/interface/EventSetup.h"
00011 #include "FWCore/Framework/interface/ESHandle.h"
00012 #include "FWCore/Framework/interface/Event.h"
00013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00014 
00015 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00016 #include "DataFormats/VertexReco/interface/Vertex.h"
00017 
00018 #include <functional>
00019 #include <algorithm>
00020 
00021 namespace {
00022 
00023 class VertexTrackPtSumFilter : public std::unary_function<reco::Vertex, bool> {
00024   public:
00025     VertexTrackPtSumFilter(double minPt):minPt_(minPt){}
00026     bool operator()(const reco::Vertex& vtx) const {
00027       double trackPtSum = 0.;
00028       for ( reco::Vertex::trackRef_iterator track = vtx.tracks_begin();
00029           track != vtx.tracks_end(); ++track ) {
00030         trackPtSum += (*track)->pt();
00031       }
00032       return trackPtSum > minPt_;
00033     }
00034   private:
00035     double minPt_;
00036 };
00037 
00038 }
00039 
00040 class RecoTauPileUpVertexSelector : public edm::EDFilter {
00041   public:
00042     explicit RecoTauPileUpVertexSelector(const edm::ParameterSet &pset);
00043     ~RecoTauPileUpVertexSelector() {}
00044     bool filter(edm::Event& evt, const edm::EventSetup& es);
00045   private:
00046     edm::InputTag src_;
00047     VertexTrackPtSumFilter vtxFilter_;
00048     bool filter_;
00049 };
00050 
00051 RecoTauPileUpVertexSelector::RecoTauPileUpVertexSelector(
00052     const edm::ParameterSet& pset):vtxFilter_(
00053       pset.getParameter<double>("minTrackSumPt")) {
00054   src_ = pset.getParameter<edm::InputTag>("src");
00055   filter_ = pset.exists("filter") ? pset.getParameter<bool>("filter") : false;
00056   produces<reco::VertexCollection>();
00057 }
00058 
00059 
00060 bool RecoTauPileUpVertexSelector::filter(
00061     edm::Event& evt, const edm::EventSetup& es) {
00062   edm::Handle<reco::VertexCollection> vertices_;
00063   evt.getByLabel(src_, vertices_);
00064   std::auto_ptr<reco::VertexCollection> output(new reco::VertexCollection);
00065   // If there is only one vertex, there are no PU vertices!
00066   if (vertices_->size() > 1) {
00067     // Copy over all the vertices that have associatd tracks with pt greater
00068     // than the threshold.  The predicate function is the VertexTrackPtSumFilter
00069     // better name: copy_if_not
00070     std::remove_copy_if(vertices_->begin()+1, vertices_->end(),
00071         std::back_inserter(*output), std::not1(vtxFilter_));
00072   }
00073   size_t nPUVtx = output->size();
00074   evt.put(output);
00075   // If 'filter' is enabled, return whether true if there are PU vertices
00076   if (!filter_)
00077     return true;
00078   else
00079     return nPUVtx;
00080 }
00081 
00082 #include "FWCore/Framework/interface/MakerMacros.h"
00083 DEFINE_FWK_MODULE(RecoTauPileUpVertexSelector);