CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DPGAnalysis/Skims/src/GoodVertexFilter.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    GoodVertexFilter
00004 // Class:      GoodVertexFilter
00005 // 
00013 //
00014 // Original Author:  Andrea RIZZI
00015 //         Created:  Mon Dec  7 18:02:10 CET 2009
00016 // $Id: GoodVertexFilter.cc,v 1.4 2010/02/28 20:10:01 wmtan Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 
00024 // user include files
00025 #include "FWCore/Framework/interface/Frameworkfwd.h"
00026 #include "FWCore/Framework/interface/EDFilter.h"
00027 
00028 #include "FWCore/Framework/interface/Event.h"
00029 #include "FWCore/Framework/interface/MakerMacros.h"
00030 
00031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00032 #include "FWCore/Utilities/interface/InputTag.h"
00033 #include "DataFormats/VertexReco/interface/Vertex.h"
00034 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00035 //
00036 // class declaration
00037 //
00038 
00039 class GoodVertexFilter : public edm::EDFilter {
00040    public:
00041       explicit GoodVertexFilter(const edm::ParameterSet&);
00042       ~GoodVertexFilter();
00043 
00044    private:
00045       virtual bool filter(edm::Event&, const edm::EventSetup&);
00046       edm::InputTag vertexSrc;        
00047       unsigned int minNDOF;
00048       double maxAbsZ;
00049       double maxd0;
00050       // ----------member data ---------------------------
00051 };
00052 
00053 GoodVertexFilter::GoodVertexFilter(const edm::ParameterSet& iConfig)
00054 {
00055   vertexSrc = iConfig.getParameter<edm::InputTag>("vertexCollection");
00056   minNDOF = iConfig.getParameter<unsigned int>("minimumNDOF");
00057   maxAbsZ = iConfig.getParameter<double>("maxAbsZ");
00058   maxd0 = iConfig.getParameter<double>("maxd0");
00059 
00060 }
00061 
00062 
00063 GoodVertexFilter::~GoodVertexFilter()
00064 {
00065 }
00066 
00067 bool
00068 GoodVertexFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
00069 {
00070  bool result = false; 
00071  edm::Handle<reco::VertexCollection> pvHandle; 
00072  iEvent.getByLabel(vertexSrc,pvHandle);
00073  const reco::VertexCollection & vertices = *pvHandle.product();
00074  for(reco::VertexCollection::const_iterator it=vertices.begin() ; it!=vertices.end() ; ++it)
00075   {
00076       if(it->ndof() > minNDOF && 
00077          ( (maxAbsZ <=0 ) || fabs(it->z()) <= maxAbsZ ) &&
00078          ( (maxd0 <=0 ) || fabs(it->position().rho()) <= maxd0 )
00079        ) result = true;
00080   }
00081 
00082    return result;
00083 }
00084 
00085 
00086 //define this as a plug-in
00087 DEFINE_FWK_MODULE(GoodVertexFilter);