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 
5 #ifndef __GCCXML__
7 #endif
9 
12 
13 
14 // make a selector for this selection
15 class PVSelector : public Selector<edm::EventBase> {
16 public:
17 
19 
20  PVSelector( edm::ParameterSet const & params ) :
21  pvSrc_ (params.getParameter<edm::InputTag>("pvSrc") ),
22  pvSel_ (params)
23  {
24  push_back("NPV", params.getParameter<int>("NPV") );
25  set("NPV");
27  indexNPV_ = index_type(&bits_, "NPV");
28  }
29 
30 #ifndef __GCCXML__
32  PVSelector(params)
33  {
34  pvSrcToken_ = iC.consumes<std::vector<reco::Vertex> >(pvSrc_);
35  }
36 #endif
37 
39  ret.set(false);
40  event.getByLabel(pvSrc_, h_primVtx);
41 
42  // check if there is a good primary vertex
43 
44  if ( h_primVtx->size() < 1 ) return false;
45 
46  // Loop over PV's and count those that pass
47  int npv = 0;
48  int _ntotal = 0;
49  mvSelPvs.clear();
50  for ( std::vector<reco::Vertex>::const_iterator ibegin = h_primVtx->begin(),
51  iend = h_primVtx->end(), i = ibegin; i != iend; ++i ) {
52  reco::Vertex const & pv = *i;
53  bool ipass = pvSel_(pv);
54  if ( ipass ) {
55  ++npv;
56  mvSelPvs.push_back(edm::Ptr<reco::Vertex>(h_primVtx,_ntotal));
57  }
58  ++_ntotal;
59  }
60 
61  // cache npv
62  mNpv = npv;
63 
64  // Set the strbitset
65  if ( npv >= cut(indexNPV_, int() ) || ignoreCut(indexNPV_) ) {
66  passCut(ret, indexNPV_);
67  }
68 
69  // Check if there is anything to ignore
70  setIgnored(ret);
71 
72  // Return status
73  bool pass = (bool)ret;
74  return pass;
75  }
76 
78 
80 
81 
82 
83  // get NPV from the last check
84  int GetNpv(void){return mNpv;}
85 
86 
87 
88  std::vector<edm::Ptr<reco::Vertex> > const &
89  GetSelectedPvs() const { return mvSelPvs; }
90 
91 
92 
93 private:
95 #ifndef __GCCXML__
97 #endif
100  std::vector<edm::Ptr<reco::Vertex> > mvSelPvs; // selected vertices
102  int mNpv; // cache number of PVs
103 };
104 
105 #endif
std::vector< edm::Ptr< reco::Vertex > > mvSelPvs
Definition: PVSelector.h:100
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:105
int i
Definition: DBlmapReader.cc:9
tuple ret
prodAgent to be discontinued
index_type indexNPV_
Definition: PVSelector.h:101
edm::Handle< std::vector< reco::Vertex > > const & vertices() const
Definition: PVSelector.h:79
pat::strbitset::index_type index_type
Definition: Selector.h:29
void setIgnored(pat::strbitset &ret)
set ignored bits
Definition: Selector.h:224
pat::strbitset retInternal_
internal ret if users don&#39;t care about return bits
Definition: Selector.h:287
PVSelector(edm::ParameterSet const &params, edm::ConsumesCollector &&iC)
Definition: PVSelector.h:31
pat::strbitset bits_
the bitset indexed by strings
Definition: Selector.h:286
void passCut(pat::strbitset &ret, std::string const &s)
Passing cuts.
Definition: Selector.h:176
bool ignoreCut(std::string const &s) const
ignore the cut at index &quot;s&quot;
Definition: Selector.h:159
virtual void push_back(std::string const &s)
This is the registration of an individual cut string.
Definition: Selector.h:46
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:24
edm::InputTag pvSrc_
Definition: PVSelector.h:94
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:38
std::vector< edm::Ptr< reco::Vertex > > const & GetSelectedPvs() const
Definition: PVSelector.h:89
pat::strbitset getBitTemplate() const
Get an empty bitset with the proper names.
Definition: Selector.h:212
PVObjectSelector pvSel_
Definition: PVSelector.h:98
edm::EDGetTokenT< std::vector< reco::Vertex > > pvSrcToken_
Definition: PVSelector.h:96
int GetNpv(void)
Definition: PVSelector.h:84
edm::Handle< std::vector< reco::Vertex > > h_primVtx
Definition: PVSelector.h:99
PVSelector(edm::ParameterSet const &params)
Definition: PVSelector.h:20
int cut(index_type const &i, int val) const
Access the int cut values at index &quot;s&quot;.
Definition: Selector.h:194