CMS 3D CMS Logo

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_
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.1 2008/07/22 12:47:02 gpetrucc Exp

Definition at line 27 of file PATSingleVertexSelector.h.


Member Typedef Documentation

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.


Member Enumeration Documentation

enum pat::PATSingleVertexSelector::Mode [private]

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_, edm::ParameterSet::exists(), edm::ParameterSet::existsAs(), First, FromBeamSpot, FromCand, edm::ParameterSet::getParameter(), hasMode_(), it, modes_, NearestToCand, parseMode(), std, vertices_, and vtxPreselection_.

00027                                                                                 {
00028    using namespace std;
00029 
00030    modes_.push_back( parseMode(iConfig.getParameter<std::string>("mode")) );
00031    if (iConfig.exists("fallbacks")) {
00032       vector<string> modes = iConfig.getParameter<vector<string> >("fallbacks");
00033       for (vector<string>::const_iterator it = modes.begin(), ed = modes.end(); it != ed; ++it) {
00034         modes_.push_back( parseMode(*it) );
00035       }
00036    }
00037    if (hasMode_(First) || hasMode_(NearestToCand)) {
00038         vertices_ = iConfig.getParameter<edm::InputTag>("vertices");
00039         if (iConfig.existsAs<string>("vertexPreselection")) {
00040             string presel = iConfig.getParameter<string>("vertexPreselection");
00041             if (!presel.empty()) vtxPreselection_ = auto_ptr<VtxSel>(new VtxSel(presel));
00042         }
00043    }
00044    if (hasMode_(NearestToCand) || hasMode_(FromCand)) {
00045         candidates_ = iConfig.getParameter<vector<edm::InputTag> >("candidates");
00046         if (iConfig.existsAs<string>("candidatePreselection")) {
00047             string presel = iConfig.getParameter<string>("candidatePreselection");
00048             if (!presel.empty()) candPreselection_ = auto_ptr<CandSel>(new CandSel(presel));
00049         }
00050     }
00051     if (hasMode_(FromBeamSpot)) {
00052         beamSpot_ = iConfig.getParameter<edm::InputTag>("beamSpot");
00053     }
00054     produces<vector<reco::Vertex> >();
00055 }

PATSingleVertexSelector::~PATSingleVertexSelector (  ) 

Definition at line 58 of file PATSingleVertexSelector.cc.

00059 {
00060 }


Member Function Documentation

bool PATSingleVertexSelector::filter ( edm::Event iEvent,
const edm::EventSetup iSetup 
) [virtual]

Implements edm::EDFilter.

Definition at line 67 of file PATSingleVertexSelector.cc.

References bestCand_, candidates_, candPreselection_, filter_(), First, FromCand, edm::Event::getByLabel(), hasMode_(), itc, modes_, NearestToCand, selVtxs_, std, vertices_, and vtxPreselection_.

00067                                                                                {
00068     using namespace edm;
00069     using namespace std;
00070 
00071     // Clear
00072     selVtxs_.clear(); bestCand_ = 0;
00073 
00074     // Gather data from the Event
00075     // -- vertex data --
00076     if (hasMode_(First) || hasMode_(NearestToCand)) {
00077         Handle<vector<reco::Vertex> > vertices;
00078         iEvent.getByLabel(vertices_, vertices);
00079         for (vector<reco::Vertex>::const_iterator itv = vertices->begin(), edv = vertices->end(); itv != edv; ++itv) {
00080             if ((vtxPreselection_.get() != 0) && !((*vtxPreselection_)(*itv)) ) continue; 
00081             selVtxs_.push_back( &*itv );
00082         }
00083     }
00084     // -- candidate data --
00085     if (hasMode_(NearestToCand) || hasMode_(FromCand)) {
00086        vector<pair<double, const reco::Candidate *> > cands;
00087        for (vector<edm::InputTag>::const_iterator itt = candidates_.begin(), edt = candidates_.end(); itt != edt; ++itt) {
00088           Handle<View<reco::Candidate> > theseCands;
00089           iEvent.getByLabel(*itt, theseCands);
00090           for (View<reco::Candidate>::const_iterator itc = theseCands->begin(), edc = theseCands->end(); itc != edc; ++itc) {
00091             if ((candPreselection_.get() != 0) && !((*candPreselection_)(*itc))) continue;
00092             cands.push_back( pair<double, const reco::Candidate *>(-itc->pt(), &*itc) );
00093           }
00094        }
00095        if (!cands.empty()) bestCand_ = cands.front().second;
00096     }
00097 
00098     // Run main mode + possible fallback modes
00099     for (std::vector<Mode>::const_iterator itm = modes_.begin(), endm = modes_.end(); itm != endm; ++itm) {
00100         if (filter_(*itm, iEvent, iSetup)) return true;
00101     }
00102     return false;
00103 
00104     // Clear
00105     selVtxs_.clear(); bestCand_ = 0;
00106 }

bool PATSingleVertexSelector::filter_ ( Mode  mode,
edm::Event iEvent,
const edm::EventSetup iSetup 
) [private]

Definition at line 109 of file PATSingleVertexSelector.cc.

References funct::abs(), beamSpot_, bestCand_, First, FromBeamSpot, FromCand, edm::Event::getByLabel(), NearestToCand, reco::Candidate::numberOfDaughters(), edm::Event::put(), HLT_VtxMuL3::result, selVtxs_, std, reco::Particle::vertex(), reco::Candidate::vertexChi2(), reco::Candidate::vertexCovariance(), reco::Candidate::vertexNdof(), and reco::Particle::vz().

Referenced by filter().

00109                                                                                            {
00110     using namespace edm;
00111     using namespace std;
00112     switch(mode) {
00113         case First: {
00114             if (selVtxs_.empty()) return false;
00115             auto_ptr<vector<reco::Vertex> > result(new vector<reco::Vertex>(1, *selVtxs_.front()));
00116             iEvent.put(result);
00117             return true;
00118             }
00119         case FromCand: {
00120             if (bestCand_ == 0) return false;
00121             reco::Vertex vtx;
00122             if (typeid(*bestCand_) == typeid(reco::VertexCompositeCandidate)) {
00123                 vtx = reco::Vertex(bestCand_->vertex(), bestCand_->vertexCovariance(), 
00124                         bestCand_->vertexChi2(), bestCand_->vertexNdof(), bestCand_->numberOfDaughters() );
00125             } else {
00126                 vtx = reco::Vertex(bestCand_->vertex(), reco::Vertex::Error(), 0, 0, 0);
00127             }
00128             auto_ptr<vector<reco::Vertex> > result(new vector<reco::Vertex>(1, vtx));
00129             iEvent.put(result);
00130             return true;
00131             }
00132         case NearestToCand: {
00133             if (selVtxs_.empty() || (bestCand_ == 0)) return false;
00134             const reco::Vertex * which = 0;
00135             float dzmin = 9999.0; 
00136             for (vector<const reco::Vertex *>::const_iterator itv = selVtxs_.begin(), edv = selVtxs_.end(); itv != edv; ++itv) {
00137                 float dz = abs((*itv)->z() - bestCand_->vz());
00138                 if (dz < dzmin) { dzmin = dz; which = *itv; }
00139             }
00140             if (which == 0) return false; // actually it should not happen, but better safe than sorry
00141             auto_ptr<vector<reco::Vertex> > result(new vector<reco::Vertex>(1, *which));
00142             iEvent.put(result);
00143             return true;
00144             }
00145         case FromBeamSpot: {
00146             Handle<reco::BeamSpot> beamSpot;
00147             iEvent.getByLabel(beamSpot_, beamSpot);
00148             reco::Vertex bs(beamSpot->position(), beamSpot->covariance3D(), 0, 0, 0);
00149             auto_ptr<vector<reco::Vertex> > result(new vector<reco::Vertex>(1, bs));
00150             iEvent.put(result);
00151             return true;
00152             }
00153         default:
00154             return false;
00155     }
00156 }

bool PATSingleVertexSelector::hasMode_ ( Mode  mode  )  const [private]

Definition at line 62 of file PATSingleVertexSelector.cc.

References find(), and modes_.

Referenced by filter(), and PATSingleVertexSelector().

00062                                                       {
00063     return (std::find(modes_.begin(), modes_.end(), mode) != modes_.end());
00064 }

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().

00012                                                         {
00013     if (mode == "firstVertex") {
00014         return First;
00015     } else if (mode == "nearestToCandidate") {
00016         return NearestToCand;
00017     } else if (mode == "fromCandidate") {
00018         return FromCand;
00019     } else if (mode == "beamSpot") {
00020         return FromBeamSpot;
00021     } else {
00022         throw cms::Exception("Configuration") << "PATSingleVertexSelector: Mode '" << mode << "' not recognized or not supported.\n";
00023     }
00024 }


Member Data Documentation

edm::InputTag pat::PATSingleVertexSelector::beamSpot_ [private]

Definition at line 50 of file PATSingleVertexSelector.h.

Referenced by filter_(), and PATSingleVertexSelector().

const reco::Candidate* pat::PATSingleVertexSelector::bestCand_ [private]

Definition at line 53 of file PATSingleVertexSelector.h.

Referenced by filter(), and filter_().

std::vector<edm::InputTag> pat::PATSingleVertexSelector::candidates_ [private]

Definition at line 47 of file PATSingleVertexSelector.h.

Referenced by filter(), and PATSingleVertexSelector().

std::auto_ptr<CandSel> pat::PATSingleVertexSelector::candPreselection_ [private]

Definition at line 49 of file PATSingleVertexSelector.h.

Referenced by filter(), and PATSingleVertexSelector().

std::vector<Mode> pat::PATSingleVertexSelector::modes_ [private]

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_().

edm::InputTag pat::PATSingleVertexSelector::vertices_ [private]

Definition at line 46 of file PATSingleVertexSelector.h.

Referenced by filter(), and PATSingleVertexSelector().

std::auto_ptr<VtxSel > pat::PATSingleVertexSelector::vtxPreselection_ [private]

Definition at line 48 of file PATSingleVertexSelector.h.

Referenced by filter(), and PATSingleVertexSelector().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:49:44 2009 for CMSSW by  doxygen 1.5.4