1 |
#include "PhysicsTools/RecoAlgos/interface/TrackWithVertexSelector.h"
|
2 |
//
|
3 |
// constructors and destructor
|
4 |
//
|
5 |
|
6 |
TrackWithVertexSelector::TrackWithVertexSelector(const edm::ParameterSet& iConfig) :
|
7 |
numberOfValidHits_(iConfig.getParameter<uint32_t>("numberOfValidHits")),
|
8 |
numberOfValidPixelHits_(iConfig.getParameter<uint32_t>("numberOfValidPixelHits")),
|
9 |
numberOfLostHits_(iConfig.getParameter<uint32_t>("numberOfLostHits")),
|
10 |
normalizedChi2_(iConfig.getParameter<double>("normalizedChi2")),
|
11 |
ptMin_(iConfig.getParameter<double>("ptMin")),
|
12 |
ptMax_(iConfig.getParameter<double>("ptMax")),
|
13 |
etaMin_(iConfig.getParameter<double>("etaMin")),
|
14 |
etaMax_(iConfig.getParameter<double>("etaMax")),
|
15 |
dzMax_(iConfig.getParameter<double>("dzMax")),
|
16 |
d0Max_(iConfig.getParameter<double>("d0Max")),
|
17 |
nVertices_(iConfig.getParameter<bool>("useVtx") ? iConfig.getParameter<uint32_t>("nVertices") : 0),
|
18 |
vertexTag_(iConfig.getParameter<edm::InputTag>("vertexTag")),
|
19 |
vtxFallback_(iConfig.getParameter<bool>("vtxFallback")),
|
20 |
zetaVtx_(iConfig.getParameter<double>("zetaVtx")),
|
21 |
rhoVtx_(iConfig.getParameter<double>("rhoVtx")) {
|
22 |
}
|
23 |
|
24 |
TrackWithVertexSelector::~TrackWithVertexSelector() { }
|
25 |
|
26 |
bool TrackWithVertexSelector::testTrack(const reco::Track &t) const {
|
27 |
using std::abs;
|
28 |
if ((t.numberOfValidHits() >= numberOfValidHits_) &&
|
29 |
(static_cast<unsigned int>(t.hitPattern().numberOfValidPixelHits()) >= numberOfValidPixelHits_) &&
|
30 |
(t.numberOfLostHits() <= numberOfLostHits_) &&
|
31 |
(t.normalizedChi2() <= normalizedChi2_) &&
|
32 |
(t.pt() >= ptMin_) &&
|
33 |
(t.pt() <= ptMax_) &&
|
34 |
(abs(t.eta()) <= etaMax_) &&
|
35 |
(abs(t.eta()) >= etaMin_) &&
|
36 |
(abs(t.dz()) <= dzMax_) &&
|
37 |
(abs(t.d0()) <= d0Max_) ) {
|
38 |
return true;
|
39 |
}
|
40 |
return false;
|
41 |
}
|
42 |
|
43 |
bool TrackWithVertexSelector::testVertices(const reco::Track &t, const reco::VertexCollection &vtxs) const {
|
44 |
bool ok = false;
|
45 |
const Point &pca = t.vertex();
|
46 |
if (vtxs.size() > 0) {
|
47 |
unsigned int tested = 1;
|
48 |
for (reco::VertexCollection::const_iterator it = vtxs.begin(), ed = vtxs.end();
|
49 |
it != ed; ++it) {
|
50 |
if (testPoint(pca, it->position())) { ok = true; break; }
|
51 |
if (tested++ >= nVertices_) break;
|
52 |
}
|
53 |
} else if (vtxFallback_) {
|
54 |
return ( (std::abs(pca.z()) < 15.9) && (pca.Rho() < 0.2) );
|
55 |
}
|
56 |
return ok;
|
57 |
}
|
58 |
|
59 |
bool TrackWithVertexSelector::operator()(const reco::Track &t, const edm::Event &evt) const {
|
60 |
using std::abs;
|
61 |
if (!testTrack(t)) return false;
|
62 |
if (nVertices_ == 0) return true;
|
63 |
edm::Handle<reco::VertexCollection> hVtx;
|
64 |
evt.getByLabel(vertexTag_, hVtx);
|
65 |
return testVertices(t, *hVtx);
|
66 |
}
|
67 |
|
68 |
bool TrackWithVertexSelector::operator()(const reco::Track &t, const reco::VertexCollection &vtxs) const {
|
69 |
using std::abs;
|
70 |
if (!testTrack(t)) return false;
|
71 |
if (nVertices_ == 0) return true;
|
72 |
return testVertices(t, vtxs);
|
73 |
}
|
74 |
|
75 |
bool TrackWithVertexSelector::testPoint(const Point &point, const Point &vtx) const {
|
76 |
using std::abs;
|
77 |
math::XYZVector d = point - vtx;
|
78 |
return ((abs(d.z()) < zetaVtx_) && (abs(d.Rho()) < rhoVtx_));
|
79 |
}
|