CMS 3D CMS Logo

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 // make a selector for this selection
14 class PVSelector : public Selector<edm::EventBase> {
15 public:
17 
18  PVSelector(edm::ParameterSet const& params) : pvSrc_(params.getParameter<edm::InputTag>("pvSrc")), pvSel_(params) {
19  push_back("NPV", params.getParameter<int>("NPV"));
20  set("NPV");
22  indexNPV_ = index_type(&bits_, "NPV");
23  }
24 
25 #ifndef __GCCXML__
27  pvSrcToken_ = iC.consumes<std::vector<reco::Vertex> >(pvSrc_);
28  }
29 #endif
30 
31  bool operator()(edm::EventBase const& event, pat::strbitset& ret) override {
32  ret.set(false);
33  event.getByLabel(pvSrc_, h_primVtx);
34 
35  // check if there is a good primary vertex
36 
37  if (h_primVtx->empty())
38  return false;
39 
40  // Loop over PV's and count those that pass
41  int npv = 0;
42  int _ntotal = 0;
43  mvSelPvs.clear();
44  for (std::vector<reco::Vertex>::const_iterator ibegin = h_primVtx->begin(), iend = h_primVtx->end(), i = ibegin;
45  i != iend;
46  ++i) {
47  reco::Vertex const& pv = *i;
48  bool ipass = pvSel_(pv);
49  if (ipass) {
50  ++npv;
51  mvSelPvs.push_back(edm::Ptr<reco::Vertex>(h_primVtx, _ntotal));
52  }
53  ++_ntotal;
54  }
55 
56  // cache npv
57  mNpv = npv;
58 
59  // Set the strbitset
60  if (npv >= cut(indexNPV_, int()) || ignoreCut(indexNPV_)) {
62  }
63 
64  // Check if there is anything to ignore
65  setIgnored(ret);
66 
67  // Return status
68  bool pass = (bool)ret;
69  return pass;
70  }
71 
73 
75 
76  // get NPV from the last check
77  int GetNpv(void) { return mNpv; }
78 
79  std::vector<edm::Ptr<reco::Vertex> > const& GetSelectedPvs() const { return mvSelPvs; }
80 
81 private:
83 #ifndef __GCCXML__
85 #endif
88  std::vector<edm::Ptr<reco::Vertex> > mvSelPvs; // selected vertices
90  int mNpv; // cache number of PVs
91 };
92 
93 #endif
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:542
Handle.h
Selector< edm::EventBase >::setIgnored
void setIgnored(pat::strbitset &ret)
set ignored bits
Definition: Selector.h:181
Selector
Functor that operates on <T>
Definition: Selector.h:22
electrons_cff.bool
bool
Definition: electrons_cff.py:366
Selector< edm::EventBase >::bits_
pat::strbitset bits_
the bitset indexed by strings
Definition: Selector.h:241
mps_fire.i
i
Definition: mps_fire.py:428
Selector< edm::EventBase >::index_type
pat::strbitset::index_type index_type
Definition: Selector.h:25
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
PVSelector::pvSrc_
edm::InputTag pvSrc_
Definition: PVSelector.h:82
Selector< edm::EventBase >::retInternal_
pat::strbitset retInternal_
internal ret if users don't care about return bits
Definition: Selector.h:242
Selector< edm::EventBase >::ignoreCut
bool ignoreCut(std::string const &s) const
ignore the cut at index "s"
Definition: Selector.h:127
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89285
pat::strbitset::index_type
Definition: strbitset.h:25
PVSelector::GetSelectedPvs
std::vector< edm::Ptr< reco::Vertex > > const & GetSelectedPvs() const
Definition: PVSelector.h:79
PVSelector::pvSrcToken_
edm::EDGetTokenT< std::vector< reco::Vertex > > pvSrcToken_
Definition: PVSelector.h:84
PVSelector::GetNpv
int GetNpv(void)
Definition: PVSelector.h:77
EventBase.h
edm::Handle
Definition: AssociativeIterator.h:50
PVSelector::operator()
bool operator()(edm::EventBase const &event, pat::strbitset &ret) override
This provides the interface for base classes to select objects.
Definition: PVSelector.h:31
PVSelector::h_primVtx
edm::Handle< std::vector< reco::Vertex > > h_primVtx
Definition: PVSelector.h:87
PVSelector::vertices
edm::Handle< std::vector< reco::Vertex > > const & vertices() const
Definition: PVSelector.h:74
Utilities.operator
operator
Definition: Utilities.py:24
PVSelector::PVSelector
PVSelector(edm::ParameterSet const &params)
Definition: PVSelector.h:18
PVSelector::pvSel_
PVObjectSelector pvSel_
Definition: PVSelector.h:86
PVObjectSelector
Definition: PVObjectSelector.h:17
Selector< edm::EventBase >::push_back
virtual void push_back(std::string const &s)
This is the registration of an individual cut string.
Definition: Selector.h:42
PVSelector::PVSelector
PVSelector()
Definition: PVSelector.h:16
PVSelector::mNpv
int mNpv
Definition: PVSelector.h:90
PVObjectSelector.h
EventSelector.h
Selector< edm::EventBase >::getBitTemplate
pat::strbitset getBitTemplate() const
Get an empty bitset with the proper names.
Definition: Selector.h:168
edm::ParameterSet
Definition: ParameterSet.h:47
PVSelector::mvSelPvs
std::vector< edm::Ptr< reco::Vertex > > mvSelPvs
Definition: PVSelector.h:88
Selector< edm::EventBase >::passCut
void passCut(pat::strbitset &ret, std::string const &s)
Passing cuts.
Definition: Selector.h:142
PVSelector::indexNPV_
index_type indexNPV_
Definition: PVSelector.h:89
PVSelector
Definition: PVSelector.h:14
MetAnalyzer.pv
def pv(vc)
Definition: MetAnalyzer.py:7
edm::Ptr
Definition: AssociationVector.h:31
pat::strbitset
Definition: strbitset.h:23
PVSelector::PVSelector
PVSelector(edm::ParameterSet const &params, edm::ConsumesCollector &&iC)
Definition: PVSelector.h:26
Selector< edm::EventBase >::cut
int cut(index_type const &i, int val) const
Access the int cut values at index "s".
Definition: Selector.h:158
edm::EventBase
Definition: EventBase.h:46
Selector< edm::EventBase >::set
void set(std::string const &s, bool val=true)
Set a given selection cut, on or off.
Definition: Selector.h:93
ConsumesCollector.h
event
Definition: event.py:1
edm::InputTag
Definition: InputTag.h:15
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
reco::Vertex
Definition: Vertex.h:35