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

virtual bool filter (edm::Event &iEvent, const edm::EventSetup &iSetup) override
 
 PATSingleVertexSelector (const edm::ParameterSet &iConfig)
 
 ~PATSingleVertexSelector ()
 
- Public Member Functions inherited from edm::stream::EDFilter<>
 EDFilter ()=default
 
- Public Member Functions inherited from edm::stream::EDFilterBase
 EDFilterBase ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDFilterBase ()
 
- 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 ()
 
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, std::unordered_multimap< std::string, edm::ProductResolverIndex > const &iIndicies, std::string const &moduleLabel)
 
virtual ~ProducerBase () noexcept(false)
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
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
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
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
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::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 28 of file PATSingleVertexSelector.h.

Member Typedef Documentation

Definition at line 40 of file PATSingleVertexSelector.h.

Definition at line 39 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 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_.

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

Definition at line 59 of file PATSingleVertexSelector.cc.

60 {
61 }

Member Function Documentation

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

Definition at line 68 of file PATSingleVertexSelector.cc.

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

68  {
69  using namespace edm;
70  using namespace std;
71 
72  // Clear
74 
75  // Gather data from the Event
76  // -- vertex data --
79  iEvent.getByToken(verticesToken_, vertices);
80  for (vector<reco::Vertex>::const_iterator itv = vertices->begin(), edv = vertices->end(); itv != edv; ++itv) {
81  if ( !(vtxPreselection_(*itv)) ) continue;
82  selVtxs_.push_back( reco::VertexRef(vertices,std::distance(vertices->begin(),itv) ) );
83  }
84  }
85  // -- candidate data --
87  vector<pair<double, reco::CandidatePtr> > cands;
88  for (vector<edm::EDGetTokenT<edm::View<reco::Candidate> > >::const_iterator itt = candidatesToken_.begin(), edt = candidatesToken_.end(); itt != edt; ++itt) {
89  Handle<View<reco::Candidate> > theseCands;
90  iEvent.getByToken(*itt, theseCands);
91  for (View<reco::Candidate>::const_iterator itc = theseCands->begin(), edc = theseCands->end(); itc != edc; ++itc) {
92  if ( !(candPreselection_(*itc)) ) continue;
93  cands.push_back( pair<double, reco::CandidatePtr>(-itc->pt(), reco::CandidatePtr(theseCands,std::distance(theseCands->begin(),itc) ) ) );
94  }
95  }
96  if (!cands.empty()) bestCand_ = cands.front().second;
97  }
98 
99  bool passes = false;
100  std::unique_ptr<vector<reco::Vertex> > result;
101  // Run main mode + possible fallback modes
102  for (std::vector<Mode>::const_iterator itm = modes_.begin(), endm = modes_.end(); itm != endm; ++itm) {
103  result = filter_(*itm, iEvent, iSetup);
104  // Check if we got any vertices. If so, take them.
105  if (result->size()) {
106  passes = true;
107  break;
108  }
109  }
110  iEvent.put(std::move(result));
111  // Check if we want to apply the EDFilter
112  if (doFilterEvents_)
113  return passes;
114  else return true;
115 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
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.
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:510
std::unique_ptr< std::vector< reco::Vertex > > PATSingleVertexSelector::filter_ ( Mode  mode,
const edm::Event iEvent,
const edm::EventSetup iSetup 
)
private

Definition at line 118 of file PATSingleVertexSelector.cc.

References funct::abs(), ecalDrivenElectronSeedsParameters_cff::beamSpot, beamSpotToken_, bestCand_, reco::BeamSpot::covariance3D(), DEFINE_FWK_MODULE, allConversions_cfi::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_, badGlobalMuonTaggersAOD_cff::vtx, and eostools::which().

Referenced by filter().

118  {
119  using namespace edm;
120  using namespace std;
121  auto result = std::make_unique<std::vector<reco::Vertex>>();
122  switch(mode) {
123  case First: {
124  if (selVtxs_.empty()) return result;
125  result->push_back(*selVtxs_.front());
126  return result;
127  }
128  case FromCand: {
129  if (bestCand_.isNull()) return result;
131  if (typeid(*bestCand_) == typeid(reco::VertexCompositeCandidate)) {
132  vtx = reco::Vertex(bestCand_->vertex(), bestCand_->vertexCovariance(),
133  bestCand_->vertexChi2(), bestCand_->vertexNdof(), bestCand_->numberOfDaughters() );
134  } else {
135  vtx = reco::Vertex(bestCand_->vertex(), reco::Vertex::Error(), 0, 0, 0);
136  }
137  result->push_back(vtx);
138  return result;
139  }
140  case NearestToCand: {
141  if (selVtxs_.empty() || (bestCand_.isNull())) return result;
143  float dzmin = 9999.0;
144  for (auto itv = selVtxs_.begin(), edv = selVtxs_.end(); itv != edv; ++itv) {
145  float dz = std::abs((*itv)->z() - bestCand_->vz());
146  if (dz < dzmin) { dzmin = dz; which = *itv; }
147  }
148  if (which.isNonnull()) // actually it should not happen, but better safe than sorry
149  result->push_back(*which);
150  return result;
151  }
152  case FromBeamSpot: {
154  iEvent.getByToken(beamSpotToken_, beamSpot);
155  reco::Vertex bs(beamSpot->position(), beamSpot->covariance3D(), 0, 0, 0);
156  result->push_back(bs);
157  return result;
158  }
159  default:
160  // Return an empty vector signifying no vertices found.
161  return result;
162  }
163 }
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:252
Covariance3DMatrix covariance3D() const
return only 3D position covariance matrix
Definition: BeamSpot.h:118
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
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:165
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
HLT enums.
const Point & position() const
position
Definition: BeamSpot.h:62
def which(cmd)
Definition: eostools.py:335
bool PATSingleVertexSelector::hasMode_ ( Mode  mode) const
private

Definition at line 63 of file PATSingleVertexSelector.cc.

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

Referenced by filter(), and PATSingleVertexSelector().

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

Definition at line 14 of file PATSingleVertexSelector.cc.

References 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 53 of file PATSingleVertexSelector.h.

Referenced by filter_(), and PATSingleVertexSelector().

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

Definition at line 56 of file PATSingleVertexSelector.h.

Referenced by filter(), and filter_().

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

Definition at line 50 of file PATSingleVertexSelector.h.

Referenced by filter(), and PATSingleVertexSelector().

const CandSel pat::PATSingleVertexSelector::candPreselection_
private

Definition at line 52 of file PATSingleVertexSelector.h.

Referenced by filter().

bool pat::PATSingleVertexSelector::doFilterEvents_
private

Definition at line 61 of file PATSingleVertexSelector.h.

Referenced by filter(), and PATSingleVertexSelector().

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

Definition at line 48 of file PATSingleVertexSelector.h.

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

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

Definition at line 55 of file PATSingleVertexSelector.h.

Referenced by filter(), and filter_().

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

Definition at line 49 of file PATSingleVertexSelector.h.

Referenced by filter(), and PATSingleVertexSelector().

const VtxSel pat::PATSingleVertexSelector::vtxPreselection_
private

Definition at line 51 of file PATSingleVertexSelector.h.

Referenced by filter().