1 |
#include "ForwardAnalysis/Utilities/interface/TrackAssociatedWithPVSelector.h"
|
2 |
|
3 |
#include "DataFormats/Common/interface/Handle.h"
|
4 |
#include "FWCore/Framework/interface/Event.h"
|
5 |
#include "FWCore/ParameterSet/interface/ParameterSet.h"
|
6 |
|
7 |
#include "DataFormats/TrackReco/interface/Track.h"
|
8 |
#include "DataFormats/VertexReco/interface/Vertex.h"
|
9 |
|
10 |
using namespace reco;
|
11 |
using forwardAnalysis::TrackAssociatedWithPVSelector;
|
12 |
|
13 |
TrackAssociatedWithPVSelector::TrackAssociatedWithPVSelector(const edm::ParameterSet& pset):
|
14 |
vertexTag_(pset.getParameter<edm::InputTag>("vertexTag")),
|
15 |
deltaZVtxMin_(pset.getParameter<double>("minDistanceFromVertex")),
|
16 |
deltaZVtxMax_(pset.getParameter<double>("maxDistanceFromVertex")){}
|
17 |
|
18 |
TrackAssociatedWithPVSelector::~TrackAssociatedWithPVSelector() {}
|
19 |
|
20 |
bool TrackAssociatedWithPVSelector::operator()(const reco::Track& track, const edm::Event& event) const {
|
21 |
edm::Handle<edm::View<Vertex> > vertexCollectionH;
|
22 |
event.getByLabel(vertexTag_,vertexCollectionH);
|
23 |
const edm::View<Vertex>& vtxColl = *(vertexCollectionH.product());
|
24 |
|
25 |
// Access primary vertex
|
26 |
const Vertex& primaryVertex = vtxColl.front();
|
27 |
bool goodPrimaryVertex = ((primaryVertex.isValid())&&(!primaryVertex.isFake()));
|
28 |
|
29 |
if(!goodPrimaryVertex) return false;
|
30 |
|
31 |
const math::XYZPoint& trackVtxPos = track.vertex();
|
32 |
const math::XYZPoint& primVtxPos = primaryVertex.position();
|
33 |
|
34 |
math::XYZVector dist = trackVtxPos - primVtxPos;
|
35 |
bool accept = (fabs(dist.z()) >= deltaZVtxMin_)&&(fabs(dist.z()) <= deltaZVtxMax_);
|
36 |
|
37 |
return accept;
|
38 |
}
|