CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/PhysicsTools/SelectorUtils/interface/PVSelector.h

Go to the documentation of this file.
00001 #ifndef Analysis_AnalysisFilters_interface_PVSelector_h
00002 #define Analysis_AnalysisFilters_interface_PVSelector_h
00003 
00004 #include "FWCore/Common/interface/EventBase.h"
00005 #include "DataFormats/Common/interface/Handle.h"
00006 
00007 #include "PhysicsTools/SelectorUtils/interface/EventSelector.h"
00008 #include "PhysicsTools/SelectorUtils/interface/PVObjectSelector.h"
00009 
00010 
00011 // make a selector for this selection
00012 class PVSelector : public Selector<edm::EventBase> {
00013 public:
00014 
00015   PVSelector() {}
00016 
00017  PVSelector( edm::ParameterSet const & params ) :
00018   pvSrc_ (params.getParameter<edm::InputTag>("pvSrc") ),
00019   pvSel_ (params) 
00020   {
00021     push_back("NPV", params.getParameter<int>("NPV") );
00022     set("NPV");
00023     retInternal_ = getBitTemplate();
00024     indexNPV_ = index_type(&bits_, "NPV");
00025   }
00026   
00027   bool operator() ( edm::EventBase const & event,  pat::strbitset & ret ) {
00028     ret.set(false);
00029     event.getByLabel(pvSrc_, h_primVtx);
00030 
00031     // check if there is a good primary vertex
00032 
00033     if ( h_primVtx->size() < 1 ) return false;
00034 
00035     // Loop over PV's and count those that pass
00036     int npv = 0;
00037     for ( std::vector<reco::Vertex>::const_iterator ibegin = h_primVtx->begin(),
00038             iend = h_primVtx->end(), i = ibegin; i != iend; ++i ) {
00039       reco::Vertex const & pv = *i;
00040       bool ipass = pvSel_(pv);
00041       if ( ipass ) {
00042         ++npv;
00043       }
00044     }
00045 
00046     // Set the strbitset
00047     if ( npv >= cut(indexNPV_, int() ) || ignoreCut(indexNPV_) ) {
00048       passCut(ret, indexNPV_);
00049     }
00050 
00051     // Check if there is anything to ignore
00052     setIgnored(ret);
00053 
00054     // Return status
00055     bool pass = (bool)ret;
00056     return pass;
00057   }
00058 
00059   using EventSelector::operator();
00060 
00061   edm::Handle<std::vector<reco::Vertex> > const & vertices() const { return h_primVtx; }
00062 
00063 private:
00064   edm::InputTag                           pvSrc_;
00065   PVObjectSelector                        pvSel_;
00066   edm::Handle<std::vector<reco::Vertex> > h_primVtx;
00067   index_type                              indexNPV_;
00068 };
00069 
00070 #endif