CMS 3D CMS Logo

Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes

pat::PATSingleVertexSelector Class Reference

Produces a list containing a single vertex selected by some criteria. More...

#include <PhysicsTools/PatAlgos/plugins/PATSingleVertexSelector.h>

Inheritance diagram for pat::PATSingleVertexSelector:
edm::EDFilter edm::ProducerBase edm::ProductRegistryHelper

List of all members.

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

bool filter_ (Mode mode, 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::CandidatebestCand_
std::vector< edm::InputTagcandidates_
std::auto_ptr< CandSelcandPreselection_
bool doFilterEvents_
std::vector< Modemodes_
std::vector< const reco::Vertex * > selVtxs_
edm::InputTag vertices_
std::auto_ptr< VtxSelvtxPreselection_

Detailed Description

Produces a list containing a single vertex selected by some criteria.

Author:
Giovanni Petrucciani
Version:
Id:
PATSingleVertexSelector.h,v 1.4 2011/01/18 13:54:10 veelken Exp

Definition at line 27 of file PATSingleVertexSelector.h.


Member Typedef Documentation

Definition at line 39 of file PATSingleVertexSelector.h.

Definition at line 38 of file PATSingleVertexSelector.h.


Member Enumeration Documentation

Enumerator:
First 
NearestToCand 
FromCand 
FromBeamSpot 

Definition at line 37 of file PATSingleVertexSelector.h.


Constructor & Destructor Documentation

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.

{
}

Member Function Documentation

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, selVtxs_, ExpressReco_HICollisions_FallBack::vertices, 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;
    }

    // Run main mode + possible fallback modes
    for (std::vector<Mode>::const_iterator itm = modes_.begin(), endm = modes_.end(); itm != endm; ++itm) {
        if (filter_(*itm, iEvent, iSetup)) return true;
    }
    if ( !doFilterEvents_ ) return true;
    return false;
}
bool PATSingleVertexSelector::filter_ ( Mode  mode,
edm::Event iEvent,
const edm::EventSetup iSetup 
) [private]

Definition at line 112 of file PATSingleVertexSelector.cc.

References abs, ExpressReco_HICollisions_FallBack::beamSpot, beamSpot_, bestCand_, First, FromBeamSpot, FromCand, edm::Event::getByLabel(), NearestToCand, reco::Candidate::numberOfDaughters(), edm::Event::put(), 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;
    switch(mode) {
        case First: {
            if (selVtxs_.empty()) return false;
            auto_ptr<vector<reco::Vertex> > result(new vector<reco::Vertex>(1, *selVtxs_.front()));
            iEvent.put(result);
            return true;
            }
        case FromCand: {
            if (bestCand_ == 0) return false;
            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);
            }
            auto_ptr<vector<reco::Vertex> > result(new vector<reco::Vertex>(1, vtx));
            iEvent.put(result);
            return true;
            }
        case NearestToCand: {
            if (selVtxs_.empty() || (bestCand_ == 0)) return false;
            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) return false; // actually it should not happen, but better safe than sorry
            auto_ptr<vector<reco::Vertex> > result(new vector<reco::Vertex>(1, *which));
            iEvent.put(result);
            return true;
            }
        case FromBeamSpot: {
            Handle<reco::BeamSpot> beamSpot;
            iEvent.getByLabel(beamSpot_, beamSpot);
            reco::Vertex bs(beamSpot->position(), beamSpot->covariance3D(), 0, 0, 0);
            auto_ptr<vector<reco::Vertex> > result(new vector<reco::Vertex>(1, bs));
            iEvent.put(result);
            return true;
            }
        default:
            return false;
    }
}
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().

                                                      {
    return (std::find(modes_.begin(), modes_.end(), mode) != modes_.end());
}
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";
    }
}

Member Data Documentation

Definition at line 50 of file PATSingleVertexSelector.h.

Referenced by filter_(), and PATSingleVertexSelector().

Definition at line 53 of file PATSingleVertexSelector.h.

Referenced by filter(), and filter_().

Definition at line 47 of file PATSingleVertexSelector.h.

Referenced by filter(), and PATSingleVertexSelector().

Definition at line 49 of file PATSingleVertexSelector.h.

Referenced by filter(), and PATSingleVertexSelector().

Definition at line 58 of file PATSingleVertexSelector.h.

Referenced by filter(), and PATSingleVertexSelector().

Definition at line 45 of file PATSingleVertexSelector.h.

Referenced by filter(), hasMode_(), and PATSingleVertexSelector().

std::vector<const reco::Vertex *> pat::PATSingleVertexSelector::selVtxs_ [private]

Definition at line 52 of file PATSingleVertexSelector.h.

Referenced by filter(), and filter_().

Definition at line 46 of file PATSingleVertexSelector.h.

Referenced by filter(), and PATSingleVertexSelector().

Definition at line 48 of file PATSingleVertexSelector.h.

Referenced by filter(), and PATSingleVertexSelector().