1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
// -*- C++ -*-
//
// Package: GoodVertexFilter
// Class: GoodVertexFilter
//
/**\class GoodVertexFilter GoodVertexFilter.cc DPGAnalysis/GoodVertexFilter/src/GoodVertexFilter.cc
Description: <one line class summary>
Implementation:
<Notes on implementation>
*/
//
// Original Author: Andrea RIZZI
// Created: Mon Dec 7 18:02:10 CET 2009
// $Id: GoodVertexFilter.cc,v 1.4 2010/02/28 20:10:01 wmtan Exp $
//
//
// system include files
#include <memory>
// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/global/EDFilter.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/Utilities/interface/EDGetToken.h"
#include "DataFormats/VertexReco/interface/Vertex.h"
#include "DataFormats/VertexReco/interface/VertexFwd.h"
//
// class declaration
//
class GoodVertexFilter : public edm::global::EDFilter<> {
public:
explicit GoodVertexFilter(const edm::ParameterSet&);
~GoodVertexFilter() override;
private:
bool filter(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
const edm::EDGetTokenT<reco::VertexCollection> vertexSrc;
const unsigned int minNDOF;
const double maxAbsZ;
const double maxd0;
// ----------member data ---------------------------
};
GoodVertexFilter::GoodVertexFilter(const edm::ParameterSet& iConfig)
: vertexSrc{consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertexCollection"))},
minNDOF{iConfig.getParameter<unsigned int>("minimumNDOF")},
maxAbsZ{iConfig.getParameter<double>("maxAbsZ")},
maxd0{iConfig.getParameter<double>("maxd0")} {}
GoodVertexFilter::~GoodVertexFilter() {}
bool GoodVertexFilter::filter(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
bool result = false;
edm::Handle<reco::VertexCollection> pvHandle;
iEvent.getByToken(vertexSrc, pvHandle);
const reco::VertexCollection& vertices = *pvHandle.product();
for (reco::VertexCollection::const_iterator it = vertices.begin(); it != vertices.end(); ++it) {
if (it->ndof() > minNDOF && ((maxAbsZ <= 0) || fabs(it->z()) <= maxAbsZ) &&
((maxd0 <= 0) || fabs(it->position().rho()) <= maxd0))
result = true;
}
return result;
}
//define this as a plug-in
DEFINE_FWK_MODULE(GoodVertexFilter);
|