00001 #include "CommonTools/RecoAlgos/interface/TrackWithVertexSelector.h" 00002 // 00003 // constructors and destructor 00004 // 00005 00006 TrackWithVertexSelector::TrackWithVertexSelector(const edm::ParameterSet& iConfig) : 00007 numberOfValidHits_(iConfig.getParameter<uint32_t>("numberOfValidHits")), 00008 numberOfValidPixelHits_(iConfig.getParameter<uint32_t>("numberOfValidPixelHits")), 00009 numberOfLostHits_(iConfig.getParameter<uint32_t>("numberOfLostHits")), 00010 normalizedChi2_(iConfig.getParameter<double>("normalizedChi2")), 00011 ptMin_(iConfig.getParameter<double>("ptMin")), 00012 ptMax_(iConfig.getParameter<double>("ptMax")), 00013 etaMin_(iConfig.getParameter<double>("etaMin")), 00014 etaMax_(iConfig.getParameter<double>("etaMax")), 00015 dzMax_(iConfig.getParameter<double>("dzMax")), 00016 d0Max_(iConfig.getParameter<double>("d0Max")), 00017 ptErrorCut_(iConfig.getParameter<double>("ptErrorCut")), 00018 quality_(iConfig.getParameter<std::string>("quality")), 00019 nVertices_(iConfig.getParameter<bool>("useVtx") ? iConfig.getParameter<uint32_t>("nVertices") : 0), 00020 vertexTag_(iConfig.getParameter<edm::InputTag>("vertexTag")), 00021 vtxFallback_(iConfig.getParameter<bool>("vtxFallback")), 00022 zetaVtx_(iConfig.getParameter<double>("zetaVtx")), 00023 rhoVtx_(iConfig.getParameter<double>("rhoVtx")) { 00024 } 00025 00026 TrackWithVertexSelector::~TrackWithVertexSelector() { } 00027 00028 bool TrackWithVertexSelector::testTrack(const reco::Track &t) const { 00029 using std::abs; 00030 if ((t.numberOfValidHits() >= numberOfValidHits_) && 00031 (static_cast<unsigned int>(t.hitPattern().numberOfValidPixelHits()) >= numberOfValidPixelHits_) && 00032 (t.numberOfLostHits() <= numberOfLostHits_) && 00033 (t.normalizedChi2() <= normalizedChi2_) && 00034 (t.ptError()/t.pt()*std::max(1.,t.normalizedChi2()) <= ptErrorCut_) && 00035 (t.quality(t.qualityByName(quality_))) && 00036 (t.pt() >= ptMin_) && 00037 (t.pt() <= ptMax_) && 00038 (abs(t.eta()) <= etaMax_) && 00039 (abs(t.eta()) >= etaMin_) && 00040 (abs(t.dz()) <= dzMax_) && 00041 (abs(t.d0()) <= d0Max_) ) { 00042 return true; 00043 } 00044 return false; 00045 } 00046 00047 bool TrackWithVertexSelector::testVertices(const reco::Track &t, const reco::VertexCollection &vtxs) const { 00048 bool ok = false; 00049 if (vtxs.size() > 0) { 00050 unsigned int tested = 1; 00051 for (reco::VertexCollection::const_iterator it = vtxs.begin(), ed = vtxs.end(); 00052 it != ed; ++it) { 00053 if ((std::abs(t.dxy(it->position())) < rhoVtx_) && 00054 (std::abs(t.dz(it->position())) < zetaVtx_)) { 00055 ok = true; break; 00056 } 00057 if (tested++ >= nVertices_) break; 00058 } 00059 } else if (vtxFallback_) { 00060 return ( (std::abs(t.vertex().z()) < 15.9) && (t.vertex().Rho() < 0.2) ); 00061 } 00062 return ok; 00063 } 00064 00065 bool TrackWithVertexSelector::operator()(const reco::Track &t, const edm::Event &evt) const { 00066 if (!testTrack(t)) return false; 00067 if (nVertices_ == 0) return true; 00068 edm::Handle<reco::VertexCollection> hVtx; 00069 evt.getByLabel(vertexTag_, hVtx); 00070 return testVertices(t, *hVtx); 00071 } 00072 00073 bool TrackWithVertexSelector::operator()(const reco::Track &t, const reco::VertexCollection &vtxs) const { 00074 if (!testTrack(t)) return false; 00075 if (nVertices_ == 0) return true; 00076 return testVertices(t, vtxs); 00077 }