CMS 3D CMS Logo

List of all members | Public Member Functions | Private Types | 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::stream::EDFilter<> edm::stream::EDFilterBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

bool filter (edm::Event &iEvent, const edm::EventSetup &iSetup) override
 
 PATSingleVertexSelector (const edm::ParameterSet &iConfig)
 
 ~PATSingleVertexSelector () override
 
- Public Member Functions inherited from edm::stream::EDFilter<>
 EDFilter ()=default
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
- Public Member Functions inherited from edm::stream::EDFilterBase
 EDFilterBase ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDFilterBase () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
 ~ProducerBase () noexcept(false) override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Types

typedef StringCutObjectSelector< reco::CandidateCandSel
 
enum  Mode { First, NearestToCand, FromCand, FromBeamSpot }
 
typedef StringCutObjectSelector< reco::VertexVtxSel
 

Private Member Functions

std::unique_ptr< std::vector< reco::Vertex > > filter_ (Mode mode, const edm::Event &iEvent, const edm::EventSetup &iSetup)
 
bool hasMode_ (Mode mode) const
 
Mode parseMode (const std::string &name) const
 

Private Attributes

edm::EDGetTokenT< reco::BeamSpotbeamSpotToken_
 
reco::CandidatePtr bestCand_
 
std::vector< edm::EDGetTokenT< edm::View< reco::Candidate > > > candidatesToken_
 
const CandSel candPreselection_
 
bool doFilterEvents_
 
std::vector< Modemodes_
 
std::vector< reco::VertexRefselVtxs_
 
edm::EDGetTokenT< std::vector< reco::Vertex > > verticesToken_
 
const VtxSel vtxPreselection_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDFilter<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 
- Public Types inherited from edm::stream::EDFilterBase
typedef EDFilterAdaptorBase ModuleType
 
- Public Types inherited from edm::ProducerBase
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex >>
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::stream::EDFilterBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::ProducerBase
ProducesCollector producesCollector ()
 
- 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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
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 28 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 27 of file PATSingleVertexSelector.cc.

References beamSpotToken_, candidatesToken_, doFilterEvents_, edm::ParameterSet::exists(), First, FromBeamSpot, FromCand, edm::ParameterSet::getParameter(), hasMode_(), modes_, NearestToCand, parseMode(), AlCaHLTBitMon_QueryRunRegistry::string, GlobalPosition_Frontier_DevDB_cff::tag, edm::vector_transform(), and verticesToken_.

28  : vtxPreselection_(iConfig.existsAs<std::string>("vertexPreselection")
29  ? iConfig.getParameter<std::string>("vertexPreselection")
30  : std::string(" 1 == 1 ")),
31  candPreselection_(iConfig.existsAs<std::string>("candidatePreselection")
32  ? iConfig.getParameter<std::string>("candidatePreselection")
33  : std::string(" 1 == 1 ")),
34  doFilterEvents_(false) {
35  using namespace std;
36 
37  modes_.push_back(parseMode(iConfig.getParameter<std::string>("mode")));
38  if (iConfig.exists("fallbacks")) {
39  vector<string> modes = iConfig.getParameter<vector<string>>("fallbacks");
40  for (vector<string>::const_iterator it = modes.begin(), ed = modes.end(); it != ed; ++it) {
41  modes_.push_back(parseMode(*it));
42  }
43  }
45  verticesToken_ = consumes<vector<reco::Vertex>>(iConfig.getParameter<edm::InputTag>("vertices"));
46  }
49  edm::vector_transform(iConfig.getParameter<vector<edm::InputTag>>("candidates"),
50  [this](edm::InputTag const &tag) { return consumes<edm::View<reco::Candidate>>(tag); });
51  }
52  if (hasMode_(FromBeamSpot)) {
53  beamSpotToken_ = consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpot"));
54  }
55 
56  if (iConfig.exists("filter"))
57  doFilterEvents_ = iConfig.getParameter<bool>("filter");
58 
59  produces<vector<reco::Vertex>>();
60 }
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:160
bool exists(std::string const &parameterName) const
checks if a parameter exists
edm::EDGetTokenT< std::vector< reco::Vertex > > verticesToken_
Mode parseMode(const std::string &name) const
std::vector< edm::EDGetTokenT< edm::View< reco::Candidate > > > candidatesToken_
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
PATSingleVertexSelector::~PATSingleVertexSelector ( )
override

Definition at line 62 of file PATSingleVertexSelector.cc.

62 {}

Member Function Documentation

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

Definition at line 68 of file PATSingleVertexSelector.cc.

References bestCand_, candidatesToken_, candPreselection_, HLT_2018_cff::cands, HLT_2018_cff::distance, doFilterEvents_, filter_(), First, FromCand, edm::Event::getByToken(), hasMode_(), modes_, eostools::move(), NearestToCand, edm::Event::put(), mps_fire::result, selVtxs_, pwdgSkimBPark_cfi::vertices, verticesToken_, and vtxPreselection_.

68  {
69  using namespace edm;
70  using namespace std;
71 
72  // Clear
73  selVtxs_.clear();
75 
76  // Gather data from the Event
77  // -- vertex data --
80  iEvent.getByToken(verticesToken_, vertices);
81  for (vector<reco::Vertex>::const_iterator itv = vertices->begin(), edv = vertices->end(); itv != edv; ++itv) {
82  if (!(vtxPreselection_(*itv)))
83  continue;
84  selVtxs_.push_back(reco::VertexRef(vertices, std::distance(vertices->begin(), itv)));
85  }
86  }
87  // -- candidate data --
89  vector<pair<double, reco::CandidatePtr>> cands;
90  for (vector<edm::EDGetTokenT<edm::View<reco::Candidate>>>::const_iterator itt = candidatesToken_.begin(),
91  edt = candidatesToken_.end();
92  itt != edt;
93  ++itt) {
94  Handle<View<reco::Candidate>> theseCands;
95  iEvent.getByToken(*itt, theseCands);
96  for (View<reco::Candidate>::const_iterator itc = theseCands->begin(), edc = theseCands->end(); itc != edc;
97  ++itc) {
98  if (!(candPreselection_(*itc)))
99  continue;
100  cands.push_back(pair<double, reco::CandidatePtr>(
101  -itc->pt(), reco::CandidatePtr(theseCands, std::distance(theseCands->begin(), itc))));
102  }
103  }
104  if (!cands.empty())
105  bestCand_ = cands.front().second;
106  }
107 
108  bool passes = false;
109  std::unique_ptr<vector<reco::Vertex>> result;
110  // Run main mode + possible fallback modes
111  for (std::vector<Mode>::const_iterator itm = modes_.begin(), endm = modes_.end(); itm != endm; ++itm) {
112  result = filter_(*itm, iEvent, iSetup);
113  // Check if we got any vertices. If so, take them.
114  if (!result->empty()) {
115  passes = true;
116  break;
117  }
118  }
119  iEvent.put(std::move(result));
120  // Check if we want to apply the EDFilter
121  if (doFilterEvents_)
122  return passes;
123  else
124  return true;
125 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
edm::EDGetTokenT< std::vector< reco::Vertex > > verticesToken_
std::vector< reco::VertexRef > selVtxs_
std::vector< edm::EDGetTokenT< edm::View< reco::Candidate > > > candidatesToken_
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:25
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
std::unique_ptr< std::vector< reco::Vertex > > filter_(Mode mode, const edm::Event &iEvent, const edm::EventSetup &iSetup)
def move(src, dest)
Definition: eostools.py:511
std::unique_ptr< std::vector< reco::Vertex > > PATSingleVertexSelector::filter_ ( Mode  mode,
const edm::Event iEvent,
const edm::EventSetup iSetup 
)
private

Definition at line 127 of file PATSingleVertexSelector.cc.

References funct::abs(), pwdgSkimBPark_cfi::beamSpot, beamSpotToken_, bestCand_, reco::BeamSpot::covariance3D(), DEFINE_FWK_MODULE, PVValHelper::dz, First, FromBeamSpot, FromCand, edm::Event::getByToken(), edm::Ref< C, T, F >::isNonnull(), edm::Ptr< T >::isNull(), NearestToCand, reco::BeamSpot::position(), mps_fire::result, selVtxs_, HltBtagValidation_cff::Vertex, badGlobalMuonTaggersAOD_cff::vtx, and eostools::which().

Referenced by filter().

129  {
130  using namespace edm;
131  using namespace std;
132  auto result = std::make_unique<std::vector<reco::Vertex>>();
133  switch (mode) {
134  case First: {
135  if (selVtxs_.empty())
136  return result;
137  result->push_back(*selVtxs_.front());
138  return result;
139  }
140  case FromCand: {
141  if (bestCand_.isNull())
142  return result;
144  auto const &bestCandDeref = *bestCand_;
145  if (typeid(bestCandDeref) == typeid(reco::VertexCompositeCandidate)) {
146  vtx = reco::Vertex(bestCand_->vertex(),
147  bestCand_->vertexCovariance(),
148  bestCand_->vertexChi2(),
149  bestCand_->vertexNdof(),
150  bestCand_->numberOfDaughters());
151  } else {
152  vtx = reco::Vertex(bestCand_->vertex(), reco::Vertex::Error(), 0, 0, 0);
153  }
154  result->push_back(vtx);
155  return result;
156  }
157  case NearestToCand: {
158  if (selVtxs_.empty() || (bestCand_.isNull()))
159  return result;
161  float dzmin = 9999.0;
162  for (auto itv = selVtxs_.begin(), edv = selVtxs_.end(); itv != edv; ++itv) {
163  float dz = std::abs((*itv)->z() - bestCand_->vz());
164  if (dz < dzmin) {
165  dzmin = dz;
166  which = *itv;
167  }
168  }
169  if (which.isNonnull()) // actually it should not happen, but better safe than sorry
170  result->push_back(*which);
171  return result;
172  }
173  case FromBeamSpot: {
175  iEvent.getByToken(beamSpotToken_, beamSpot);
176  reco::Vertex bs(beamSpot->position(), beamSpot->covariance3D(), 0, 0, 0);
177  result->push_back(bs);
178  return result;
179  }
180  default:
181  // Return an empty vector signifying no vertices found.
182  return result;
183  }
184 }
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
Covariance3DMatrix covariance3D() const
return only 3D position covariance matrix
Definition: BeamSpot.h:112
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:43
std::vector< reco::VertexRef > selVtxs_
bool isNull() const
Checks for null.
Definition: Ptr.h:142
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
HLT enums.
const Point & position() const
position
Definition: BeamSpot.h:59
def which(cmd)
Definition: eostools.py:336
bool PATSingleVertexSelector::hasMode_ ( Mode  mode) const
private

Definition at line 64 of file PATSingleVertexSelector.cc.

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

Referenced by filter(), and PATSingleVertexSelector().

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

Definition at line 12 of file PATSingleVertexSelector.cc.

References Exception, First, FromBeamSpot, FromCand, and NearestToCand.

Referenced by PATSingleVertexSelector().

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

Member Data Documentation

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

Definition at line 52 of file PATSingleVertexSelector.h.

Referenced by filter_(), and PATSingleVertexSelector().

reco::CandidatePtr pat::PATSingleVertexSelector::bestCand_
private

Definition at line 55 of file PATSingleVertexSelector.h.

Referenced by filter(), and filter_().

std::vector<edm::EDGetTokenT<edm::View<reco::Candidate> > > pat::PATSingleVertexSelector::candidatesToken_
private

Definition at line 49 of file PATSingleVertexSelector.h.

Referenced by filter(), and PATSingleVertexSelector().

const CandSel pat::PATSingleVertexSelector::candPreselection_
private

Definition at line 51 of file PATSingleVertexSelector.h.

Referenced by filter().

bool pat::PATSingleVertexSelector::doFilterEvents_
private

Definition at line 60 of file PATSingleVertexSelector.h.

Referenced by filter(), and PATSingleVertexSelector().

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

Definition at line 47 of file PATSingleVertexSelector.h.

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

std::vector<reco::VertexRef> pat::PATSingleVertexSelector::selVtxs_
private

Definition at line 54 of file PATSingleVertexSelector.h.

Referenced by filter(), and filter_().

edm::EDGetTokenT<std::vector<reco::Vertex> > pat::PATSingleVertexSelector::verticesToken_
private

Definition at line 48 of file PATSingleVertexSelector.h.

Referenced by filter(), and PATSingleVertexSelector().

const VtxSel pat::PATSingleVertexSelector::vtxPreselection_
private

Definition at line 50 of file PATSingleVertexSelector.h.

Referenced by filter().