CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
pat::helper::VertexingHelper Class Reference

Produces and/or checks pat::VertexAssociation's. More...

#include "PhysicsTools/PatAlgos/interface/VertexingHelper.h"

Public Member Functions

bool enabled () const
 returns true if this was given a non dummy configuration More...
 
void newEvent (const edm::Event &event)
 To be called for each new event, reads in the vertex collection. More...
 
void newEvent (const edm::Event &event, const edm::EventSetup &setup)
 
template<typename AnyCandRef >
pat::VertexAssociation operator() (const AnyCandRef &) const
 
 VertexingHelper ()
 
 VertexingHelper (const edm::ParameterSet &iConfig, edm::ConsumesCollector &&iC)
 

Private Member Functions

pat::VertexAssociation associate (const reco::Candidate &) const
 
reco::TrackBaseRef getTrack_ (const reco::Candidate &c) const
 Get out the track from the Candidate / RecoCandidate / PFCandidate. More...
 

Private Attributes

pat::VertexAssociationSelector assoSelector_
 selector of associations More...
 
bool enabled_
 true if it has non null configuration More...
 
bool playback_
 true if it's just reading the associations from the event More...
 
edm::ESHandle< TransientTrackBuilderttBuilder_
 
bool useTracks_
 use tracks inside candidates More...
 
edm::EDGetTokenT< edm::ValueMap< pat::VertexAssociation > > vertexAssociationsToken_
 
edm::Handle< edm::ValueMap< pat::VertexAssociation > > vertexAssoMap_
 
edm::Handle< reco::VertexCollectionvertexHandle_
 
edm::EDGetTokenT< reco::VertexCollectionverticesToken_
 

Detailed Description

Produces and/or checks pat::VertexAssociation's.

The VertexingHelper produces pat::VertexAssociation, or reads them from the event, and can use them to select if a candidate is good or not.

Author
Giovanni Petrucciani
Version
Id
VertexingHelper.h,v 1.3 2008/06/06 14:13:40 gpetrucc Exp

Definition at line 50 of file VertexingHelper.h.

Constructor & Destructor Documentation

◆ VertexingHelper() [1/2]

pat::helper::VertexingHelper::VertexingHelper ( )
inline

Definition at line 52 of file VertexingHelper.h.

52 : enabled_(false) {}

◆ VertexingHelper() [2/2]

pat::helper::VertexingHelper::VertexingHelper ( const edm::ParameterSet iConfig,
edm::ConsumesCollector &&  iC 
)

Definition at line 11 of file VertexingHelper.cc.

11  {
12  if (!iConfig.empty()) {
13  enabled_ = true;
14  if (iConfig.existsAs<edm::InputTag>("vertexAssociations") == iConfig.existsAs<edm::InputTag>("vertices")) {
15  throw cms::Exception("Configuration") << "VertexingHelper: you must configure either 'vertices' (to produce "
16  "associations) or 'vertexAssociations' (to read them from disk), "
17  << "you can't specify both, nor you can specify none!\n";
18  }
19 
20  if (iConfig.existsAs<edm::InputTag>("vertexAssociations")) {
21  playback_ = true;
23  iConfig.getParameter<edm::InputTag>("vertexAssociations"));
24  }
25  if (iConfig.existsAs<edm::InputTag>("vertices")) { // vertex have been specified, so run on the fly
26  playback_ = false;
28  // ------ MODE ------------------
29  useTracks_ = iConfig.getParameter<bool>("useTracks");
30  // ------ CUTS (fully optional) ------------------
31  }
32  assoSelector_ = reco::modules::make<pat::VertexAssociationSelector>(iConfig);
33  } else {
34  enabled_ = false;
35  }
36 }

References assoSelector_, edm::ParameterSet::empty(), enabled_, Exception, edm::ParameterSet::existsAs(), edm::ParameterSet::getParameter(), playback_, useTracks_, vertexAssociationsToken_, and verticesToken_.

Member Function Documentation

◆ associate()

pat::VertexAssociation pat::helper::VertexingHelper::associate ( const reco::Candidate c) const
private

Try to associated this candidate to a vertex. If no association is found passing all cuts, return a null association

Definition at line 52 of file VertexingHelper.cc.

52  {
53  if (playback_)
54  throw cms::Exception("Configuration")
55  << "VertexingHelper: if this module was configured to read associations from the event,"
56  << " you must use 'operator()' passing a candidate ref, and not 'associate()' directly!\n";
57 
58  reco::VertexCollection::const_iterator vtx, end;
59  size_t ivtx;
62  if (useTracks_) {
63  if (!ttBuilder_.isValid())
64  throw cms::Exception("Configuration")
65  << "VertexingHelper: If you use 'useTracks', you must call newEvent(iEvent,iSetup)!\n";
66  tk = getTrack_(c);
67  if (tk.isNull())
68  return pat::VertexAssociation();
69  tt = ttBuilder_->build(*tk);
70  }
71  for (vtx = vertexHandle_->begin(), end = vertexHandle_->end(), ivtx = 0; vtx != end; ++vtx, ++ivtx) {
73  if (useTracks_ == false) {
74  association.setDistances(c.vertex(), vtx->position(), vtx->error());
75  } else {
76  GlobalPoint vtxGP(vtx->x(), vtx->y(), vtx->z()); // need to convert XYZPoint to GlobalPoint
77  TrajectoryStateClosestToPoint tscp = tt.trajectoryStateClosestToPoint(vtxGP);
78  GlobalPoint trackPos = tscp.theState().position();
79  AlgebraicSymMatrix33 trackErr = tscp.theState().cartesianError().matrix().Sub<AlgebraicSymMatrix33>(0, 0);
80  association.setDistances(trackPos, vtx->position(), trackErr + vtx->error());
81  }
83  return association;
84  }
85  return pat::VertexAssociation();
86 }

References c, mps_fire::end, Exception, edm::RefToBase< T >::isNull(), groupFilesInBlocks::tt, and extraflags_cff::vtx.

◆ enabled()

bool pat::helper::VertexingHelper::enabled ( ) const
inline

returns true if this was given a non dummy configuration

Definition at line 56 of file VertexingHelper.h.

56 { return enabled_; }

References enabled_.

Referenced by pat::PATGenericParticleProducer::produce().

◆ getTrack_()

reco::TrackBaseRef pat::helper::VertexingHelper::getTrack_ ( const reco::Candidate c) const
private

Get out the track from the Candidate / RecoCandidate / PFCandidate.

Definition at line 88 of file VertexingHelper.cc.

88  {
89  const reco::RecoCandidate *rc = dynamic_cast<const reco::RecoCandidate *>(&c);
90  if (rc != nullptr) {
91  return rc->bestTrackRef();
92  }
93  const reco::PFCandidate *pfc = dynamic_cast<const reco::PFCandidate *>(&c);
94  if (pfc != nullptr) {
95  return reco::TrackBaseRef(pfc->trackRef());
96  }
97 
98  return reco::TrackBaseRef();
99 }

References reco::RecoCandidate::bestTrackRef(), c, and reco::PFCandidate::trackRef().

◆ newEvent() [1/2]

void pat::helper::VertexingHelper::newEvent ( const edm::Event event)

To be called for each new event, reads in the vertex collection.

Definition at line 38 of file VertexingHelper.cc.

38  {
39  if (playback_) {
41  } else {
42  iEvent.getByToken(verticesToken_, vertexHandle_);
43  }
44 }

References iEvent.

Referenced by pat::PATVertexAssociationProducer::produce(), and pat::PATGenericParticleProducer::produce().

◆ newEvent() [2/2]

void pat::helper::VertexingHelper::newEvent ( const edm::Event event,
const edm::EventSetup setup 
)

To be called for each new event, reads in the vertex collection and the tracking info You need this if 'useTrack' is true

Definition at line 46 of file VertexingHelper.cc.

46  {
48  if (!playback_)
49  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", ttBuilder_);
50 }

References edm::EventSetup::get(), get, and iEvent.

◆ operator()()

template<typename AnyCandRef >
pat::VertexAssociation pat::helper::VertexingHelper::operator() ( const AnyCandRef &  cand) const

Return true if this candidate is associated to a valid vertex AnyCandRef should be a Ref<>, RefToBase<> or Ptr to a Candidate object

Definition at line 101 of file VertexingHelper.h.

101  {
102  if (playback_) {
103  const pat::VertexAssociation &assoc = (*vertexAssoMap_)[cand];
105  } else {
106  return associate(*cand);
107  }
108  }

References trackingPlots::assoc.

Member Data Documentation

◆ assoSelector_

pat::VertexAssociationSelector pat::helper::VertexingHelper::assoSelector_
private

selector of associations

Definition at line 78 of file VertexingHelper.h.

Referenced by VertexingHelper().

◆ enabled_

bool pat::helper::VertexingHelper::enabled_
private

true if it has non null configuration

Definition at line 72 of file VertexingHelper.h.

Referenced by enabled(), and VertexingHelper().

◆ playback_

bool pat::helper::VertexingHelper::playback_
private

true if it's just reading the associations from the event

Definition at line 75 of file VertexingHelper.h.

Referenced by VertexingHelper().

◆ ttBuilder_

edm::ESHandle<TransientTrackBuilder> pat::helper::VertexingHelper::ttBuilder_
private

Definition at line 85 of file VertexingHelper.h.

◆ useTracks_

bool pat::helper::VertexingHelper::useTracks_
private

use tracks inside candidates

Definition at line 84 of file VertexingHelper.h.

Referenced by VertexingHelper().

◆ vertexAssociationsToken_

edm::EDGetTokenT<edm::ValueMap<pat::VertexAssociation> > pat::helper::VertexingHelper::vertexAssociationsToken_
private

Definition at line 88 of file VertexingHelper.h.

Referenced by VertexingHelper().

◆ vertexAssoMap_

edm::Handle<edm::ValueMap<pat::VertexAssociation> > pat::helper::VertexingHelper::vertexAssoMap_
private

Definition at line 89 of file VertexingHelper.h.

◆ vertexHandle_

edm::Handle<reco::VertexCollection> pat::helper::VertexingHelper::vertexHandle_
private

Definition at line 82 of file VertexingHelper.h.

◆ verticesToken_

edm::EDGetTokenT<reco::VertexCollection> pat::helper::VertexingHelper::verticesToken_
private

Definition at line 81 of file VertexingHelper.h.

Referenced by VertexingHelper().

reco::PFCandidate::trackRef
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:408
edm::RefToBase::isNull
bool isNull() const
Checks for null.
Definition: RefToBase.h:295
AlgebraicSymMatrix33
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepSym< double, 3 > > AlgebraicSymMatrix33
Definition: AlgebraicROOTObjects.h:21
pat::helper::VertexingHelper::vertexAssociationsToken_
edm::EDGetTokenT< edm::ValueMap< pat::VertexAssociation > > vertexAssociationsToken_
Definition: VertexingHelper.h:88
groupFilesInBlocks.tt
int tt
Definition: groupFilesInBlocks.py:144
reco::VertexCollection
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
pat::helper::VertexingHelper::vertexHandle_
edm::Handle< reco::VertexCollection > vertexHandle_
Definition: VertexingHelper.h:82
pat::helper::VertexingHelper::verticesToken_
edm::EDGetTokenT< reco::VertexCollection > verticesToken_
Definition: VertexingHelper.h:81
reco::TrackBaseRef
edm::RefToBase< reco::Track > TrackBaseRef
persistent reference to a Track, using views
Definition: TrackFwd.h:35
edm::ParameterSet::existsAs
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:171
edm::Ref< VertexCollection >
trackingPlots.assoc
assoc
Definition: trackingPlots.py:184
pat::helper::VertexingHelper::useTracks_
bool useTracks_
use tracks inside candidates
Definition: VertexingHelper.h:84
pat::helper::VertexingHelper::vertexAssoMap_
edm::Handle< edm::ValueMap< pat::VertexAssociation > > vertexAssoMap_
Definition: VertexingHelper.h:89
mps_fire.end
end
Definition: mps_fire.py:242
TransientTrackRecord
Definition: TransientTrackRecord.h:11
pat::helper::VertexingHelper::getTrack_
reco::TrackBaseRef getTrack_(const reco::Candidate &c) const
Get out the track from the Candidate / RecoCandidate / PFCandidate.
Definition: VertexingHelper.cc:88
pat::helper::VertexingHelper::playback_
bool playback_
true if it's just reading the associations from the event
Definition: VertexingHelper.h:75
edm::ConsumesCollector::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: ConsumesCollector.h:55
pat::helper::VertexingHelper::assoSelector_
pat::VertexAssociationSelector assoSelector_
selector of associations
Definition: VertexingHelper.h:78
Point3DBase< float, GlobalTag >
pat::helper::VertexingHelper::newEvent
void newEvent(const edm::Event &event)
To be called for each new event, reads in the vertex collection.
Definition: VertexingHelper.cc:38
pat::helper::VertexingHelper::ttBuilder_
edm::ESHandle< TransientTrackBuilder > ttBuilder_
Definition: VertexingHelper.h:85
cand
Definition: decayParser.h:32
iEvent
int iEvent
Definition: GenABIO.cc:224
TrajectoryStateClosestToPoint
Definition: TrajectoryStateClosestToPoint.h:18
reco::RecoCandidate
Definition: RecoCandidate.h:20
get
#define get
edm::ESHandleBase::isValid
bool isValid() const
Definition: ESHandle.h:44
pat::VertexAssociation
Analysis-level structure for vertex-related information.
Definition: Vertexing.h:25
hgcal::association
std::tuple< layerClusterToCaloParticle, caloParticleToLayerCluster > association
Definition: LayerClusterAssociatorByEnergyScoreImpl.h:44
reco::TransientTrack
Definition: TransientTrack.h:19
extraflags_cff.vtx
vtx
Definition: extraflags_cff.py:18
edm::ValueMap
Definition: ValueMap.h:107
Exception
Definition: hltDiff.cc:245
pat::helper::VertexingHelper::associate
pat::VertexAssociation associate(const reco::Candidate &) const
Definition: VertexingHelper.cc:52
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::RefToBase< reco::Track >
pat::helper::VertexingHelper::enabled_
bool enabled_
true if it has non null configuration
Definition: VertexingHelper.h:72
reco::PFCandidate
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
TransientTrackBuilder::build
reco::TransientTrack build(const reco::Track *p) const
Definition: TransientTrackBuilder.cc:20
cms::Exception
Definition: Exception.h:70
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
edm::InputTag
Definition: InputTag.h:15
edm::ParameterSet::empty
bool empty() const
Definition: ParameterSet.h:201
reco::RecoCandidate::bestTrackRef
virtual TrackBaseRef bestTrackRef() const
best track RefToBase
Definition: RecoCandidate.cc:45