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

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
 
 EDFilter (const EDFilter &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDFilteroperator= (const EDFilter &)=delete
 
- Public Member Functions inherited from edm::stream::EDFilterBase
 EDFilterBase ()
 
 EDFilterBase (const EDFilterBase &)=delete
 
ModuleDescription const & moduleDescription () const
 
const EDFilterBaseoperator= (const EDFilterBase &)=delete
 
 ~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
 
std::vector< bool > const & recordProvenanceList () 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)
 
TypeLabelList const & typeLabelList () const
 used by the fwk to register the list of products of this module More...
 
 ~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
 
ESResolverIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESResolverIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (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::array< std::vector< ModuleDescription const *> *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, 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
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProductResolverIndices 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<>
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 
- Public Types inherited from edm::stream::EDFilterBase
typedef EDFilterAdaptorBase ModuleType
 
- Public Types inherited from edm::ProducerBase
template<typename T >
using BranchAliasSetterT = ProductRegistryHelper::BranchAliasSetterT< T >
 
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
template<Transition Tr = Transition::Event>
auto produces (std::string instanceName) noexcept
 declare what type of product will make and with which optional label More...
 
template<Transition B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<BranchType B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces ()
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces ()
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces ()
 
template<Transition Tr = Transition::Event>
auto produces () noexcept
 
ProducesCollector producesCollector ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
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)
 
void resetItemsToGetFrom (BranchType iType)
 

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.cc.

Member Typedef Documentation

◆ CandSel

Definition at line 38 of file PATSingleVertexSelector.cc.

◆ VtxSel

Definition at line 37 of file PATSingleVertexSelector.cc.

Member Enumeration Documentation

◆ Mode

Constructor & Destructor Documentation

◆ PATSingleVertexSelector()

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

Definition at line 82 of file PATSingleVertexSelector.cc.

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

83  : vtxPreselection_(iConfig.existsAs<std::string>("vertexPreselection")
84  ? iConfig.getParameter<std::string>("vertexPreselection")
85  : std::string(" 1 == 1 ")),
86  candPreselection_(iConfig.existsAs<std::string>("candidatePreselection")
87  ? iConfig.getParameter<std::string>("candidatePreselection")
88  : std::string(" 1 == 1 ")),
89  doFilterEvents_(false) {
90  using namespace std;
91 
92  modes_.push_back(parseMode(iConfig.getParameter<std::string>("mode")));
93  if (iConfig.exists("fallbacks")) {
94  vector<string> modes = iConfig.getParameter<vector<string>>("fallbacks");
95  for (vector<string>::const_iterator it = modes.begin(), ed = modes.end(); it != ed; ++it) {
96  modes_.push_back(parseMode(*it));
97  }
98  }
100  verticesToken_ = consumes<vector<reco::Vertex>>(iConfig.getParameter<edm::InputTag>("vertices"));
101  }
104  edm::vector_transform(iConfig.getParameter<vector<edm::InputTag>>("candidates"),
105  [this](edm::InputTag const &tag) { return consumes<edm::View<reco::Candidate>>(tag); });
106  }
107  if (hasMode_(FromBeamSpot)) {
108  beamSpotToken_ = consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpot"));
109  }
110 
111  if (iConfig.exists("filter"))
112  doFilterEvents_ = iConfig.getParameter<bool>("filter");
113 
114  produces<vector<reco::Vertex>>();
115 }
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
bool exists(std::string const &parameterName) const
checks if a parameter exists
edm::EDGetTokenT< std::vector< reco::Vertex > > verticesToken_
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:172
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
Mode parseMode(const std::string &name) const
std::vector< edm::EDGetTokenT< edm::View< reco::Candidate > > > candidatesToken_

◆ ~PATSingleVertexSelector()

PATSingleVertexSelector::~PATSingleVertexSelector ( )
override

Definition at line 117 of file PATSingleVertexSelector.cc.

117 {}

Member Function Documentation

◆ filter()

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

Implements edm::stream::EDFilterBase.

Definition at line 123 of file PATSingleVertexSelector.cc.

References bestCand_, candidatesToken_, candPreselection_, HLT_2024v13_cff::cands, HLT_2024v13_cff::distance, doFilterEvents_, filter_(), First, FromCand, hasMode_(), iEvent, modes_, eostools::move(), NearestToCand, mps_fire::result, selVtxs_, trackerHitRTTI::vector, AlignmentTracksFromVertexSelector_cfi::vertices, verticesToken_, and vtxPreselection_.

123  {
124  using namespace edm;
125  using namespace std;
126 
127  // Clear
128  selVtxs_.clear();
130 
131  // Gather data from the Event
132  // -- vertex data --
135  iEvent.getByToken(verticesToken_, vertices);
136  for (vector<reco::Vertex>::const_iterator itv = vertices->begin(), edv = vertices->end(); itv != edv; ++itv) {
137  if (!(vtxPreselection_(*itv)))
138  continue;
139  selVtxs_.push_back(reco::VertexRef(vertices, std::distance(vertices->begin(), itv)));
140  }
141  }
142  // -- candidate data --
144  vector<pair<double, reco::CandidatePtr>> cands;
145  for (vector<edm::EDGetTokenT<edm::View<reco::Candidate>>>::const_iterator itt = candidatesToken_.begin(),
146  edt = candidatesToken_.end();
147  itt != edt;
148  ++itt) {
149  Handle<View<reco::Candidate>> theseCands;
150  iEvent.getByToken(*itt, theseCands);
151  for (View<reco::Candidate>::const_iterator itc = theseCands->begin(), edc = theseCands->end(); itc != edc;
152  ++itc) {
153  if (!(candPreselection_(*itc)))
154  continue;
155  cands.push_back(pair<double, reco::CandidatePtr>(
156  -itc->pt(), reco::CandidatePtr(theseCands, std::distance(theseCands->begin(), itc))));
157  }
158  }
159  if (!cands.empty())
160  bestCand_ = cands.front().second;
161  }
162 
163  bool passes = false;
164  std::unique_ptr<vector<reco::Vertex>> result;
165  // Run main mode + possible fallback modes
166  for (std::vector<Mode>::const_iterator itm = modes_.begin(), endm = modes_.end(); itm != endm; ++itm) {
167  result = filter_(*itm, iEvent, iSetup);
168  // Check if we got any vertices. If so, take them.
169  if (!result->empty()) {
170  passes = true;
171  break;
172  }
173  }
174  iEvent.put(std::move(result));
175  // Check if we want to apply the EDFilter
176  if (doFilterEvents_)
177  return passes;
178  else
179  return true;
180 }
edm::EDGetTokenT< std::vector< reco::Vertex > > verticesToken_
std::vector< reco::VertexRef > selVtxs_
int iEvent
Definition: GenABIO.cc:224
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:88
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

◆ filter_()

std::unique_ptr< std::vector< reco::Vertex > > PATSingleVertexSelector::filter_ ( Mode  mode,
const edm::Event iEvent,
const edm::EventSetup iSetup 
)
private

Definition at line 182 of file PATSingleVertexSelector.cc.

References funct::abs(), pwdgSkimBPark_cfi::beamSpot, beamSpotToken_, bestCand_, cms::cuda::bs, PVValHelper::dz, First, FromBeamSpot, FromCand, iEvent, edm::Ptr< T >::isNull(), ALCARECOPromptCalibProdSiPixelAli0T_cff::mode, NearestToCand, mps_fire::result, selVtxs_, HltBtagValidation_cff::Vertex, L1BJetProducer_cff::vtx, and eostools::which().

Referenced by filter().

184  {
185  using namespace edm;
186  using namespace std;
187  auto result = std::make_unique<std::vector<reco::Vertex>>();
188  switch (mode) {
189  case First: {
190  if (selVtxs_.empty())
191  return result;
192  result->push_back(*selVtxs_.front());
193  return result;
194  }
195  case FromCand: {
196  if (bestCand_.isNull())
197  return result;
199  auto const &bestCandDeref = *bestCand_;
200  if (typeid(bestCandDeref) == typeid(reco::VertexCompositeCandidate)) {
201  vtx = reco::Vertex(bestCand_->vertex(),
202  bestCand_->vertexCovariance(),
203  bestCand_->vertexChi2(),
204  bestCand_->vertexNdof(),
205  bestCand_->numberOfDaughters());
206  } else {
207  vtx = reco::Vertex(bestCand_->vertex(), reco::Vertex::Error(), 0, 0, 0);
208  }
209  result->push_back(vtx);
210  return result;
211  }
212  case NearestToCand: {
213  if (selVtxs_.empty() || (bestCand_.isNull()))
214  return result;
216  float dzmin = 9999.0;
217  for (auto itv = selVtxs_.begin(), edv = selVtxs_.end(); itv != edv; ++itv) {
218  float dz = std::abs((*itv)->z() - bestCand_->vz());
219  if (dz < dzmin) {
220  dzmin = dz;
221  which = *itv;
222  }
223  }
224  if (which.isNonnull()) // actually it should not happen, but better safe than sorry
225  result->push_back(*which);
226  return result;
227  }
228  case FromBeamSpot: {
230  iEvent.getByToken(beamSpotToken_, beamSpot);
231  reco::Vertex bs(beamSpot->position(), beamSpot->covariance3D(), 0, 0, 0);
232  result->push_back(bs);
233  return result;
234  }
235  default:
236  // Return an empty vector signifying no vertices found.
237  return result;
238  }
239 }
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:45
std::vector< reco::VertexRef > selVtxs_
int iEvent
Definition: GenABIO.cc:224
bool isNull() const
Checks for null.
Definition: Ptr.h:142
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
HLT enums.
def which(cmd)
Definition: eostools.py:336

◆ hasMode_()

bool PATSingleVertexSelector::hasMode_ ( Mode  mode) const
private

Definition at line 119 of file PATSingleVertexSelector.cc.

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

Referenced by filter(), and PATSingleVertexSelector().

119  {
120  return (std::find(modes_.begin(), modes_.end(), mode) != modes_.end());
121 }
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19

◆ parseMode()

PATSingleVertexSelector::Mode PATSingleVertexSelector::parseMode ( const std::string &  name) const
private

Definition at line 67 of file PATSingleVertexSelector.cc.

References Exception, First, FromBeamSpot, FromCand, ALCARECOPromptCalibProdSiPixelAli0T_cff::mode, and NearestToCand.

Referenced by PATSingleVertexSelector().

67  {
68  if (mode == "firstVertex") {
69  return First;
70  } else if (mode == "nearestToCandidate") {
71  return NearestToCand;
72  } else if (mode == "fromCandidate") {
73  return FromCand;
74  } else if (mode == "beamSpot") {
75  return FromBeamSpot;
76  } else {
77  throw cms::Exception("Configuration")
78  << "PATSingleVertexSelector: Mode '" << mode << "' not recognized or not supported.\n";
79  }
80 }

Member Data Documentation

◆ beamSpotToken_

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

Definition at line 52 of file PATSingleVertexSelector.cc.

Referenced by filter_(), and PATSingleVertexSelector().

◆ bestCand_

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

Definition at line 55 of file PATSingleVertexSelector.cc.

Referenced by filter(), and filter_().

◆ candidatesToken_

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

Definition at line 49 of file PATSingleVertexSelector.cc.

Referenced by filter(), and PATSingleVertexSelector().

◆ candPreselection_

const CandSel pat::PATSingleVertexSelector::candPreselection_
private

Definition at line 51 of file PATSingleVertexSelector.cc.

Referenced by filter().

◆ doFilterEvents_

bool pat::PATSingleVertexSelector::doFilterEvents_
private

Definition at line 60 of file PATSingleVertexSelector.cc.

Referenced by filter(), and PATSingleVertexSelector().

◆ modes_

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

Definition at line 47 of file PATSingleVertexSelector.cc.

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

◆ selVtxs_

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

Definition at line 54 of file PATSingleVertexSelector.cc.

Referenced by filter(), and filter_().

◆ verticesToken_

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

Definition at line 48 of file PATSingleVertexSelector.cc.

Referenced by filter(), and PATSingleVertexSelector().

◆ vtxPreselection_

const VtxSel pat::PATSingleVertexSelector::vtxPreselection_
private

Definition at line 50 of file PATSingleVertexSelector.cc.

Referenced by filter().