CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PVSelector.h
Go to the documentation of this file.
1 #ifndef Analysis_AnalysisFilters_interface_PVSelector_h
2 #define Analysis_AnalysisFilters_interface_PVSelector_h
3 
6 
9 
10 
11 // make a selector for this selection
12 class PVSelector : public Selector<edm::EventBase> {
13 public:
14 
16 
17  PVSelector( edm::ParameterSet const & params ) :
18  pvSrc_ (params.getParameter<edm::InputTag>("pvSrc") ),
19  pvSel_ (params)
20  {
21  push_back("NPV", params.getParameter<int>("NPV") );
22  set("NPV");
24  indexNPV_ = index_type(&bits_, "NPV");
25  }
26 
28  ret.set(false);
29  event.getByLabel(pvSrc_, h_primVtx);
30 
31  // check if there is a good primary vertex
32 
33  if ( h_primVtx->size() < 1 ) return false;
34 
35  // Loop over PV's and count those that pass
36  int npv = 0;
37  int _ntotal = 0;
38  mvSelPvs.clear();
39  for ( std::vector<reco::Vertex>::const_iterator ibegin = h_primVtx->begin(),
40  iend = h_primVtx->end(), i = ibegin; i != iend; ++i ) {
41  reco::Vertex const & pv = *i;
42  bool ipass = pvSel_(pv);
43  if ( ipass ) {
44  ++npv;
45  mvSelPvs.push_back(edm::Ptr<reco::Vertex>(h_primVtx,_ntotal));
46  }
47  ++_ntotal;
48  }
49 
50  // cache npv
51  mNpv = npv;
52 
53  // Set the strbitset
54  if ( npv >= cut(indexNPV_, int() ) || ignoreCut(indexNPV_) ) {
55  passCut(ret, indexNPV_);
56  }
57 
58  // Check if there is anything to ignore
59  setIgnored(ret);
60 
61  // Return status
62  bool pass = (bool)ret;
63  return pass;
64  }
65 
67 
69 
70 
71 
72  // get NPV from the last check
73  int GetNpv(void){return mNpv;}
74 
75 
76 
77  std::vector<edm::Ptr<reco::Vertex> > const &
78  GetSelectedPvs() const { return mvSelPvs; }
79 
80 
81 
82 private:
86  std::vector<edm::Ptr<reco::Vertex> > mvSelPvs; // selected vertices
88  int mNpv; // cache number of PVs
89 };
90 
91 #endif
std::vector< edm::Ptr< reco::Vertex > > mvSelPvs
Definition: PVSelector.h:86
T getParameter(std::string const &) const
void set(std::string const &s, bool val=true)
Set a given selection cut, on or off.
Definition: Selector.h:106
int i
Definition: DBlmapReader.cc:9
index_type indexNPV_
Definition: PVSelector.h:87
edm::Handle< std::vector< reco::Vertex > > const & vertices() const
Definition: PVSelector.h:68
pat::strbitset::index_type index_type
Definition: Selector.h:30
void setIgnored(pat::strbitset &ret)
set ignored bits
Definition: Selector.h:225
pat::strbitset retInternal_
internal ret if users don&#39;t care about return bits
Definition: Selector.h:288
pat::strbitset bits_
the bitset indexed by strings
Definition: Selector.h:287
void passCut(pat::strbitset &ret, std::string const &s)
Passing cuts.
Definition: Selector.h:177
bool ignoreCut(std::string const &s) const
ignore the cut at index &quot;s&quot;
Definition: Selector.h:160
virtual void push_back(std::string const &s)
This is the registration of an individual cut string.
Definition: Selector.h:47
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
Functor that operates on &lt;T&gt;
Definition: Selector.h:25
edm::InputTag pvSrc_
Definition: PVSelector.h:83
strbitset & set(bool val=true)
set method of all bits
Definition: strbitset.h:144
bool operator()(edm::EventBase const &event, pat::strbitset &ret)
This provides the interface for base classes to select objects.
Definition: PVSelector.h:27
std::vector< edm::Ptr< reco::Vertex > > const & GetSelectedPvs() const
Definition: PVSelector.h:78
pat::strbitset getBitTemplate() const
Get an empty bitset with the proper names.
Definition: Selector.h:213
PVObjectSelector pvSel_
Definition: PVSelector.h:84
int GetNpv(void)
Definition: PVSelector.h:73
edm::Handle< std::vector< reco::Vertex > > h_primVtx
Definition: PVSelector.h:85
PVSelector(edm::ParameterSet const &params)
Definition: PVSelector.h:17
int cut(index_type const &i, int val) const
Access the int cut values at index &quot;s&quot;.
Definition: Selector.h:195