CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | 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::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

virtual bool filter (edm::Event &iEvent, const edm::EventSetup &iSetup) override
 
 PATSingleVertexSelector (const edm::ParameterSet &iConfig)
 
 ~PATSingleVertexSelector ()
 
- Public Member Functions inherited from edm::EDFilter
 EDFilter ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDFilter ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

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::EDGetTokenT< reco::BeamSpotbeamSpotToken_
 
const reco::CandidatebestCand_
 
std::vector< edm::EDGetTokenT
< edm::View< reco::Candidate > > > 
candidatesToken_
 
std::auto_ptr< CandSelcandPreselection_
 
bool doFilterEvents_
 
std::vector< Modemodes_
 
std::vector< const reco::Vertex * > selVtxs_
 
edm::EDGetTokenT< std::vector
< reco::Vertex > > 
verticesToken_
 
std::auto_ptr< VtxSelvtxPreselection_
 

Additional Inherited Members

- Public Types inherited from edm::EDFilter
typedef EDFilter ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Static Public Member Functions inherited from edm::EDFilter
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
- Protected Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

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

Author
Giovanni Petrucciani
Version
Id:
PATSingleVertexSelector.h,v 1.5 2011/06/15 11:47:25 friis Exp

Definition at line 26 of file PATSingleVertexSelector.h.

Member Typedef Documentation

Definition at line 38 of file PATSingleVertexSelector.h.

Definition at line 37 of file PATSingleVertexSelector.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

PATSingleVertexSelector::PATSingleVertexSelector ( const edm::ParameterSet iConfig)
explicit

Definition at line 29 of file PATSingleVertexSelector.cc.

References candidatesToken_, candPreselection_, edm::EDConsumerBase::consumes(), edm::ParameterSet::exists(), edm::ParameterSet::existsAs(), First, FromCand, edm::ParameterSet::getParameter(), hasMode_(), modes_, NearestToCand, parseMode(), AlCaHLTBitMon_QueryRunRegistry::string, GlobalPosition_Frontier_DevDB_cff::tag, edm::vector_transform(), verticesToken_, and vtxPreselection_.

30  : doFilterEvents_(false)
31 {
32  using namespace std;
33 
34  modes_.push_back( parseMode(iConfig.getParameter<std::string>("mode")) );
35  if (iConfig.exists("fallbacks")) {
36  vector<string> modes = iConfig.getParameter<vector<string> >("fallbacks");
37  for (vector<string>::const_iterator it = modes.begin(), ed = modes.end(); it != ed; ++it) {
38  modes_.push_back( parseMode(*it) );
39  }
40  }
42  verticesToken_ = consumes<vector<reco::Vertex> >(iConfig.getParameter<edm::InputTag>("vertices"));
43  if (iConfig.existsAs<string>("vertexPreselection")) {
44  string presel = iConfig.getParameter<string>("vertexPreselection");
45  if (!presel.empty()) vtxPreselection_ = auto_ptr<VtxSel>(new VtxSel(presel));
46  }
47  }
49  candidatesToken_ = edm::vector_transform(iConfig.getParameter<vector<edm::InputTag> >("candidates"), [this](edm::InputTag const & tag){return consumes<edm::View<reco::Candidate> >(tag);});
50  if (iConfig.existsAs<string>("candidatePreselection")) {
51  string presel = iConfig.getParameter<string>("candidatePreselection");
52  if (!presel.empty()) candPreselection_ = auto_ptr<CandSel>(new CandSel(presel));
53  }
54  }
55  if (hasMode_(FromBeamSpot)) {
56  beamSpotToken_ = consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpot"));
57  }
58 
59  if ( iConfig.exists("filter") ) doFilterEvents_ = iConfig.getParameter<bool>("filter");
60 
61  produces<vector<reco::Vertex> >();
62 }
T getParameter(std::string const &) const
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:185
std::auto_ptr< VtxSel > vtxPreselection_
static Mode parseMode(const std::string &name)
bool exists(std::string const &parameterName) const
checks if a parameter exists
edm::EDGetTokenT< std::vector< reco::Vertex > > verticesToken_
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
std::auto_ptr< CandSel > candPreselection_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
std::vector< edm::EDGetTokenT< edm::View< reco::Candidate > > > candidatesToken_
StringCutObjectSelector< reco::Vertex > VtxSel
StringCutObjectSelector< reco::Candidate > CandSel
PATSingleVertexSelector::~PATSingleVertexSelector ( )

Definition at line 65 of file PATSingleVertexSelector.cc.

66 {
67 }

Member Function Documentation

bool PATSingleVertexSelector::filter ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overridevirtual

Implements edm::EDFilter.

Definition at line 74 of file PATSingleVertexSelector.cc.

References bestCand_, candidatesToken_, candPreselection_, doFilterEvents_, filter_(), First, FromCand, edm::Event::getByToken(), hasMode_(), modes_, NearestToCand, edm::Event::put(), query::result, selVtxs_, HLT_25ns14e33_v1_cff::vertices, verticesToken_, and vtxPreselection_.

74  {
75  using namespace edm;
76  using namespace std;
77 
78  // Clear
79  selVtxs_.clear(); bestCand_ = 0;
80 
81  // Gather data from the Event
82  // -- vertex data --
85  iEvent.getByToken(verticesToken_, vertices);
86  for (vector<reco::Vertex>::const_iterator itv = vertices->begin(), edv = vertices->end(); itv != edv; ++itv) {
87  if ((vtxPreselection_.get() != 0) && !((*vtxPreselection_)(*itv)) ) continue;
88  selVtxs_.push_back( &*itv );
89  }
90  }
91  // -- candidate data --
93  vector<pair<double, const reco::Candidate *> > cands;
94  for (vector<edm::EDGetTokenT<edm::View<reco::Candidate> > >::const_iterator itt = candidatesToken_.begin(), edt = candidatesToken_.end(); itt != edt; ++itt) {
95  Handle<View<reco::Candidate> > theseCands;
96  iEvent.getByToken(*itt, theseCands);
97  for (View<reco::Candidate>::const_iterator itc = theseCands->begin(), edc = theseCands->end(); itc != edc; ++itc) {
98  if ((candPreselection_.get() != 0) && !((*candPreselection_)(*itc))) continue;
99  cands.push_back( pair<double, const reco::Candidate *>(-itc->pt(), &*itc) );
100  }
101  }
102  if (!cands.empty()) bestCand_ = cands.front().second;
103  }
104 
105  bool passes = false;
106  auto_ptr<vector<reco::Vertex> > result;
107  // Run main mode + possible fallback modes
108  for (std::vector<Mode>::const_iterator itm = modes_.begin(), endm = modes_.end(); itm != endm; ++itm) {
109  result = filter_(*itm, iEvent, iSetup);
110  // Check if we got any vertices. If so, take them.
111  if (result->size()) {
112  passes = true;
113  break;
114  }
115  }
116  iEvent.put(result);
117  // Check if we want to apply the EDFilter
118  if (doFilterEvents_)
119  return passes;
120  else return true;
121 }
std::auto_ptr< VtxSel > vtxPreselection_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
std::auto_ptr< std::vector< reco::Vertex > > filter_(Mode mode, const edm::Event &iEvent, const edm::EventSetup &iSetup)
edm::EDGetTokenT< std::vector< reco::Vertex > > verticesToken_
std::auto_ptr< CandSel > candPreselection_
std::vector< const reco::Vertex * > selVtxs_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
tuple result
Definition: query.py:137
std::vector< edm::EDGetTokenT< edm::View< reco::Candidate > > > candidatesToken_
const reco::Candidate * bestCand_
std::auto_ptr< std::vector< reco::Vertex > > PATSingleVertexSelector::filter_ ( Mode  mode,
const edm::Event iEvent,
const edm::EventSetup iSetup 
)
private

Definition at line 124 of file PATSingleVertexSelector.cc.

References funct::abs(), SiPixelRawToDigiRegional_cfi::beamSpot, beamSpotToken_, bestCand_, First, FromBeamSpot, FromCand, edm::Event::getByToken(), NearestToCand, reco::Candidate::numberOfDaughters(), query::result, selVtxs_, reco::Candidate::vertex(), reco::Candidate::vertexChi2(), reco::Candidate::vertexCovariance(), reco::Candidate::vertexNdof(), reco::Candidate::vz(), and eostools::which().

Referenced by filter().

124  {
125  using namespace edm;
126  using namespace std;
127  std::auto_ptr<std::vector<reco::Vertex> > result(
128  new std::vector<reco::Vertex>());
129  switch(mode) {
130  case First: {
131  if (selVtxs_.empty()) return result;
132  result->push_back(*selVtxs_.front());
133  return result;
134  }
135  case FromCand: {
136  if (bestCand_ == 0) return result;
137  reco::Vertex vtx;
138  if (typeid(*bestCand_) == typeid(reco::VertexCompositeCandidate)) {
141  } else {
142  vtx = reco::Vertex(bestCand_->vertex(), reco::Vertex::Error(), 0, 0, 0);
143  }
144  result->push_back(vtx);
145  return result;
146  }
147  case NearestToCand: {
148  if (selVtxs_.empty() || (bestCand_ == 0)) return result;
149  const reco::Vertex * which = 0;
150  float dzmin = 9999.0;
151  for (vector<const reco::Vertex *>::const_iterator itv = selVtxs_.begin(), edv = selVtxs_.end(); itv != edv; ++itv) {
152  float dz = std::abs((*itv)->z() - bestCand_->vz());
153  if (dz < dzmin) { dzmin = dz; which = *itv; }
154  }
155  if (which != 0) // actually it should not happen, but better safe than sorry
156  result->push_back(*which);
157  return result;
158  }
159  case FromBeamSpot: {
161  iEvent.getByToken(beamSpotToken_, beamSpot);
162  reco::Vertex bs(beamSpot->position(), beamSpot->covariance3D(), 0, 0, 0);
163  result->push_back(bs);
164  return result;
165  }
166  default:
167  // Return an empty vector signifying no vertices found.
168  return result;
169  }
170 }
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
def which
Definition: eostools.py:333
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:43
virtual size_type numberOfDaughters() const =0
number of daughters
std::vector< const reco::Vertex * > selVtxs_
virtual double vertexChi2() const =0
chi-squares
tuple result
Definition: query.py:137
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
virtual const Point & vertex() const =0
vertex position
virtual double vz() const =0
z coordinate of vertex position
virtual double vertexCovariance(int i, int j) const =0
(i, j)-th element of error matrix, i, j = 0, ... 2
const reco::Candidate * bestCand_
virtual double vertexNdof() const =0
bool PATSingleVertexSelector::hasMode_ ( Mode  mode) const
private

Definition at line 69 of file PATSingleVertexSelector.cc.

References spr::find(), alignBH_cfg::mode, and modes_.

Referenced by filter(), and PATSingleVertexSelector().

69  {
70  return (std::find(modes_.begin(), modes_.end(), mode) != modes_.end());
71 }
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
PATSingleVertexSelector::Mode PATSingleVertexSelector::parseMode ( const std::string &  name)
staticprivate

Definition at line 14 of file PATSingleVertexSelector.cc.

References edm::hlt::Exception, First, FromBeamSpot, FromCand, and NearestToCand.

Referenced by PATSingleVertexSelector().

14  {
15  if (mode == "firstVertex") {
16  return First;
17  } else if (mode == "nearestToCandidate") {
18  return NearestToCand;
19  } else if (mode == "fromCandidate") {
20  return FromCand;
21  } else if (mode == "beamSpot") {
22  return FromBeamSpot;
23  } else {
24  throw cms::Exception("Configuration") << "PATSingleVertexSelector: Mode '" << mode << "' not recognized or not supported.\n";
25  }
26 }

Member Data Documentation

edm::EDGetTokenT<reco::BeamSpot> pat::PATSingleVertexSelector::beamSpotToken_
private

Definition at line 50 of file PATSingleVertexSelector.h.

Referenced by filter_().

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

Definition at line 53 of file PATSingleVertexSelector.h.

Referenced by filter(), and filter_().

std::vector<edm::EDGetTokenT<edm::View<reco::Candidate> > > pat::PATSingleVertexSelector::candidatesToken_
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().

bool pat::PATSingleVertexSelector::doFilterEvents_
private

Definition at line 58 of file PATSingleVertexSelector.h.

Referenced by filter().

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::EDGetTokenT<std::vector<reco::Vertex> > pat::PATSingleVertexSelector::verticesToken_
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().