Produces a list containing a single vertex selected by some criteria. More...
#include <PhysicsTools/PatAlgos/plugins/PATSingleVertexSelector.h>
Public Member Functions | |
virtual bool | filter (edm::Event &iEvent, const edm::EventSetup &iSetup) |
PATSingleVertexSelector (const edm::ParameterSet &iConfig) | |
~PATSingleVertexSelector () | |
Private Types | |
typedef StringCutObjectSelector < reco::Candidate > | CandSel |
enum | Mode { First, NearestToCand, FromCand, FromBeamSpot } |
typedef StringCutObjectSelector < reco::Vertex > | VtxSel |
Private Member Functions | |
std::auto_ptr< std::vector < reco::Vertex > > | filter_ (Mode mode, const edm::Event &iEvent, const edm::EventSetup &iSetup) |
bool | hasMode_ (Mode mode) const |
Static Private Member Functions | |
static Mode | parseMode (const std::string &name) |
Private Attributes | |
edm::InputTag | beamSpot_ |
const reco::Candidate * | bestCand_ |
std::vector< edm::InputTag > | candidates_ |
std::auto_ptr< CandSel > | candPreselection_ |
bool | doFilterEvents_ |
std::vector< Mode > | modes_ |
std::vector< const reco::Vertex * > | selVtxs_ |
edm::InputTag | vertices_ |
std::auto_ptr< VtxSel > | vtxPreselection_ |
Produces a list containing a single vertex selected by some criteria.
Definition at line 27 of file PATSingleVertexSelector.h.
typedef StringCutObjectSelector<reco::Candidate> pat::PATSingleVertexSelector::CandSel [private] |
Definition at line 39 of file PATSingleVertexSelector.h.
typedef StringCutObjectSelector<reco::Vertex> pat::PATSingleVertexSelector::VtxSel [private] |
Definition at line 38 of file PATSingleVertexSelector.h.
enum pat::PATSingleVertexSelector::Mode [private] |
Definition at line 37 of file PATSingleVertexSelector.h.
{ First, NearestToCand, FromCand, FromBeamSpot };
PATSingleVertexSelector::PATSingleVertexSelector | ( | const edm::ParameterSet & | iConfig | ) | [explicit] |
Definition at line 27 of file PATSingleVertexSelector.cc.
References beamSpot_, candidates_, candPreselection_, doFilterEvents_, edm::ParameterSet::exists(), edm::ParameterSet::existsAs(), First, FromBeamSpot, FromCand, edm::ParameterSet::getParameter(), hasMode_(), modes_, NearestToCand, parseMode(), vertices_, and vtxPreselection_.
: doFilterEvents_(false) { using namespace std; modes_.push_back( parseMode(iConfig.getParameter<std::string>("mode")) ); if (iConfig.exists("fallbacks")) { vector<string> modes = iConfig.getParameter<vector<string> >("fallbacks"); for (vector<string>::const_iterator it = modes.begin(), ed = modes.end(); it != ed; ++it) { modes_.push_back( parseMode(*it) ); } } if (hasMode_(First) || hasMode_(NearestToCand)) { vertices_ = iConfig.getParameter<edm::InputTag>("vertices"); if (iConfig.existsAs<string>("vertexPreselection")) { string presel = iConfig.getParameter<string>("vertexPreselection"); if (!presel.empty()) vtxPreselection_ = auto_ptr<VtxSel>(new VtxSel(presel)); } } if (hasMode_(NearestToCand) || hasMode_(FromCand)) { candidates_ = iConfig.getParameter<vector<edm::InputTag> >("candidates"); if (iConfig.existsAs<string>("candidatePreselection")) { string presel = iConfig.getParameter<string>("candidatePreselection"); if (!presel.empty()) candPreselection_ = auto_ptr<CandSel>(new CandSel(presel)); } } if (hasMode_(FromBeamSpot)) { beamSpot_ = iConfig.getParameter<edm::InputTag>("beamSpot"); } if ( iConfig.exists("filter") ) doFilterEvents_ = iConfig.getParameter<bool>("filter"); produces<vector<reco::Vertex> >(); }
PATSingleVertexSelector::~PATSingleVertexSelector | ( | ) |
Definition at line 63 of file PATSingleVertexSelector.cc.
{ }
bool PATSingleVertexSelector::filter | ( | edm::Event & | iEvent, |
const edm::EventSetup & | iSetup | ||
) | [virtual] |
Implements edm::EDFilter.
Definition at line 72 of file PATSingleVertexSelector.cc.
References bestCand_, candidates_, candPreselection_, doFilterEvents_, filter_(), First, FromCand, edm::Event::getByLabel(), hasMode_(), modes_, NearestToCand, edm::Event::put(), query::result, selVtxs_, vertices_, and vtxPreselection_.
{ using namespace edm; using namespace std; // Clear selVtxs_.clear(); bestCand_ = 0; // Gather data from the Event // -- vertex data -- if (hasMode_(First) || hasMode_(NearestToCand)) { Handle<vector<reco::Vertex> > vertices; iEvent.getByLabel(vertices_, vertices); for (vector<reco::Vertex>::const_iterator itv = vertices->begin(), edv = vertices->end(); itv != edv; ++itv) { if ((vtxPreselection_.get() != 0) && !((*vtxPreselection_)(*itv)) ) continue; selVtxs_.push_back( &*itv ); } } // -- candidate data -- if (hasMode_(NearestToCand) || hasMode_(FromCand)) { vector<pair<double, const reco::Candidate *> > cands; for (vector<edm::InputTag>::const_iterator itt = candidates_.begin(), edt = candidates_.end(); itt != edt; ++itt) { Handle<View<reco::Candidate> > theseCands; iEvent.getByLabel(*itt, theseCands); for (View<reco::Candidate>::const_iterator itc = theseCands->begin(), edc = theseCands->end(); itc != edc; ++itc) { if ((candPreselection_.get() != 0) && !((*candPreselection_)(*itc))) continue; cands.push_back( pair<double, const reco::Candidate *>(-itc->pt(), &*itc) ); } } if (!cands.empty()) bestCand_ = cands.front().second; } bool passes = false; auto_ptr<vector<reco::Vertex> > result; // Run main mode + possible fallback modes for (std::vector<Mode>::const_iterator itm = modes_.begin(), endm = modes_.end(); itm != endm; ++itm) { result = filter_(*itm, iEvent, iSetup); // Check if we got any vertices. If so, take them. if (result->size()) { passes = true; break; } } iEvent.put(result); // Check if we want to apply the EDFilter if (doFilterEvents_) return passes; else return true; }
std::auto_ptr< std::vector< reco::Vertex > > PATSingleVertexSelector::filter_ | ( | Mode | mode, |
const edm::Event & | iEvent, | ||
const edm::EventSetup & | iSetup | ||
) | [private] |
Definition at line 122 of file PATSingleVertexSelector.cc.
References abs, SiPixelRawToDigiRegional_cfi::beamSpot, beamSpot_, bestCand_, First, FromBeamSpot, FromCand, edm::Event::getByLabel(), NearestToCand, reco::Candidate::numberOfDaughters(), query::result, selVtxs_, reco::Candidate::vertex(), reco::Candidate::vertexChi2(), reco::Candidate::vertexCovariance(), reco::Candidate::vertexNdof(), and reco::Candidate::vz().
Referenced by filter().
{ using namespace edm; using namespace std; std::auto_ptr<std::vector<reco::Vertex> > result( new std::vector<reco::Vertex>()); switch(mode) { case First: { if (selVtxs_.empty()) return result; result->push_back(*selVtxs_.front()); return result; } case FromCand: { if (bestCand_ == 0) return result; reco::Vertex vtx; if (typeid(*bestCand_) == typeid(reco::VertexCompositeCandidate)) { vtx = reco::Vertex(bestCand_->vertex(), bestCand_->vertexCovariance(), bestCand_->vertexChi2(), bestCand_->vertexNdof(), bestCand_->numberOfDaughters() ); } else { vtx = reco::Vertex(bestCand_->vertex(), reco::Vertex::Error(), 0, 0, 0); } result->push_back(vtx); return result; } case NearestToCand: { if (selVtxs_.empty() || (bestCand_ == 0)) return result; const reco::Vertex * which = 0; float dzmin = 9999.0; for (vector<const reco::Vertex *>::const_iterator itv = selVtxs_.begin(), edv = selVtxs_.end(); itv != edv; ++itv) { float dz = std::abs((*itv)->z() - bestCand_->vz()); if (dz < dzmin) { dzmin = dz; which = *itv; } } if (which != 0) // actually it should not happen, but better safe than sorry result->push_back(*which); return result; } case FromBeamSpot: { Handle<reco::BeamSpot> beamSpot; iEvent.getByLabel(beamSpot_, beamSpot); reco::Vertex bs(beamSpot->position(), beamSpot->covariance3D(), 0, 0, 0); result->push_back(bs); return result; } default: // Return an empty vector signifying no vertices found. return result; } }
bool PATSingleVertexSelector::hasMode_ | ( | Mode | mode | ) | const [private] |
Definition at line 67 of file PATSingleVertexSelector.cc.
References spr::find(), mode, and modes_.
Referenced by filter(), and PATSingleVertexSelector().
PATSingleVertexSelector::Mode PATSingleVertexSelector::parseMode | ( | const std::string & | name | ) | [static, private] |
Definition at line 12 of file PATSingleVertexSelector.cc.
References Exception, First, FromBeamSpot, FromCand, and NearestToCand.
Referenced by PATSingleVertexSelector().
{ if (mode == "firstVertex") { return First; } else if (mode == "nearestToCandidate") { return NearestToCand; } else if (mode == "fromCandidate") { return FromCand; } else if (mode == "beamSpot") { return FromBeamSpot; } else { throw cms::Exception("Configuration") << "PATSingleVertexSelector: Mode '" << mode << "' not recognized or not supported.\n"; } }
Definition at line 51 of file PATSingleVertexSelector.h.
Referenced by filter_(), and PATSingleVertexSelector().
const reco::Candidate* pat::PATSingleVertexSelector::bestCand_ [private] |
Definition at line 54 of file PATSingleVertexSelector.h.
std::vector<edm::InputTag> pat::PATSingleVertexSelector::candidates_ [private] |
Definition at line 48 of file PATSingleVertexSelector.h.
Referenced by filter(), and PATSingleVertexSelector().
std::auto_ptr<CandSel> pat::PATSingleVertexSelector::candPreselection_ [private] |
Definition at line 50 of file PATSingleVertexSelector.h.
Referenced by filter(), and PATSingleVertexSelector().
bool pat::PATSingleVertexSelector::doFilterEvents_ [private] |
Definition at line 59 of file PATSingleVertexSelector.h.
Referenced by filter(), and PATSingleVertexSelector().
std::vector<Mode> pat::PATSingleVertexSelector::modes_ [private] |
Definition at line 46 of file PATSingleVertexSelector.h.
Referenced by filter(), hasMode_(), and PATSingleVertexSelector().
std::vector<const reco::Vertex *> pat::PATSingleVertexSelector::selVtxs_ [private] |
Definition at line 53 of file PATSingleVertexSelector.h.
Definition at line 47 of file PATSingleVertexSelector.h.
Referenced by filter(), and PATSingleVertexSelector().
std::auto_ptr<VtxSel > pat::PATSingleVertexSelector::vtxPreselection_ [private] |
Definition at line 49 of file PATSingleVertexSelector.h.
Referenced by filter(), and PATSingleVertexSelector().