CMS 3D CMS Logo

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>

List of all members.

Public Member Functions

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

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.

Private Attributes

pat::VertexAssociationSelector assoSelector_
 selector of associations
bool enabled_
 true if it has non null configuration
bool playback_
 true if it's just reading the associations from the event
edm::ESHandle
< TransientTrackBuilder
ttBuilder_
bool useTracks_
 use tracks inside candidates
edm::InputTag vertexAssociations_
edm::Handle< edm::ValueMap
< pat::VertexAssociation > > 
vertexAssoMap_
edm::Handle
< reco::VertexCollection
vertexHandle_
edm::InputTag vertices_

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.1 2008/07/22 12:47:01 gpetrucc Exp

Definition at line 45 of file VertexingHelper.h.


Constructor & Destructor Documentation

pat::helper::VertexingHelper::VertexingHelper ( ) [inline]

Definition at line 47 of file VertexingHelper.h.

: enabled_(false) {}
pat::helper::VertexingHelper::VertexingHelper ( const edm::ParameterSet iConfig)

Definition at line 11 of file VertexingHelper.cc.

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

{
    if (!iConfig.empty()) { 
        enabled_ = true;
        if ( iConfig.existsAs<edm::InputTag>("vertexAssociations") == iConfig.existsAs<edm::InputTag>("vertices")) {
            throw cms::Exception("Configuration") <<
                "VertexingHelper: you must configure either 'vertices' (to produce associations) or 'vertexAssociations' (to read them from disk), " <<
                "you can't specify both, nor you can specify none!\n";
        }
            
        if (iConfig.existsAs<edm::InputTag>("vertexAssociations")) {
            playback_ = true;
            vertexAssociations_ = iConfig.getParameter<edm::InputTag>("vertexAssociations");
        }
        if (iConfig.existsAs<edm::InputTag>("vertices")) { // vertex have been specified, so run on the fly
            playback_ = false;
            vertices_ = iConfig.getParameter<edm::InputTag>("vertices");
            // ------ MODE ------------------
            useTracks_ = iConfig.getParameter<bool>("useTracks");
            // ------ CUTS (fully optional) ------------------
        }
        assoSelector_ = reco::modules::make<pat::VertexAssociationSelector>(iConfig);
    } else {
        enabled_ = false;
    }
}

Member Function Documentation

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 55 of file VertexingHelper.cc.

References end, Exception, edm::RefToBase< T >::isNull(), pat::VertexAssociation::setDistances(), reco::TransientTrack::trajectoryStateClosestToPoint(), groupFilesInBlocks::tt, and reco::Candidate::vertex().

                                                                {
    if (playback_) throw cms::Exception("Configuration") << "VertexingHelper: if this module was configured to read associations from the event," << 
                                                            " you must use 'operator()' passing a candidate ref, and not 'associate()' directly!\n";

    reco::VertexCollection::const_iterator vtx, end;
    size_t ivtx;
    reco::TrackBaseRef tk; 
    reco::TransientTrack tt;
    if (useTracks_) { 
        if (!ttBuilder_.isValid()) throw cms::Exception("Configuration") << "VertexingHelper: If you use 'useTracks', you must call newEvent(iEvent,iSetup)!\n";
        tk = getTrack_(c); 
        if (tk.isNull()) return pat::VertexAssociation(); 
        tt = ttBuilder_->build(*tk);
    }
    for (vtx = vertexHandle_->begin(), end = vertexHandle_->end(), ivtx = 0; vtx != end; ++vtx, ++ivtx) {
        pat::VertexAssociation association(reco::VertexRef(vertexHandle_, ivtx), tk);
        if (useTracks_ == false) {
            association.setDistances(c.vertex(), vtx->position(), vtx->error());
        } else {
            GlobalPoint vtxGP(vtx->x(), vtx->y(), vtx->z()); // need to convert XYZPoint to GlobalPoint
            TrajectoryStateClosestToPoint tscp = tt.trajectoryStateClosestToPoint(vtxGP); 
            GlobalPoint          trackPos = tscp.theState().position();
            AlgebraicSymMatrix33 trackErr = tscp.theState().cartesianError().matrix().Sub<AlgebraicSymMatrix33>(0,0);
            association.setDistances(trackPos, vtx->position(), trackErr + vtx->error());
        }
        if (assoSelector_(association)) return association;
    }
    return pat::VertexAssociation();
}
bool pat::helper::VertexingHelper::enabled ( ) const [inline]

returns true if this was given a non dummy configuration

Definition at line 51 of file VertexingHelper.h.

References enabled_.

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

{  return enabled_; }
reco::TrackBaseRef pat::helper::VertexingHelper::getTrack_ ( const reco::Candidate c) const [private]

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

Definition at line 85 of file VertexingHelper.cc.

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

                                                                                  {
    const reco::RecoCandidate   *rc  = dynamic_cast<const reco::RecoCandidate *>(&c);
    if (rc  != 0)  { return rc->bestTrackRef(); }
    const reco::PFCandidate *pfc = dynamic_cast<const reco::PFCandidate *>(&c);
    if (pfc != 0) { return reco::TrackBaseRef(pfc->trackRef()); }

    return reco::TrackBaseRef();
}
void pat::helper::VertexingHelper::newEvent ( const edm::Event event)

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

Definition at line 39 of file VertexingHelper.cc.

References edm::Event::getByLabel().

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

                                                         {
    if (playback_) {
        iEvent.getByLabel(vertexAssociations_, vertexAssoMap_);
    } else {
        iEvent.getByLabel(vertices_, vertexHandle_);
    }
}
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 48 of file VertexingHelper.cc.

References edm::EventSetup::get().

                                                                                       {
    newEvent(iEvent);
    if (!playback_) iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", ttBuilder_);
}
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 97 of file VertexingHelper.h.

    {
        if (playback_) {
            const pat::VertexAssociation &assoc = (*vertexAssoMap_)[cand];
            return assoSelector_(assoc) ? assoc : pat::VertexAssociation();
        } else {
            return associate( *cand );
        }

    }

Member Data Documentation

selector of associations

Definition at line 73 of file VertexingHelper.h.

Referenced by VertexingHelper().

true if it has non null configuration

Definition at line 67 of file VertexingHelper.h.

Referenced by enabled(), and VertexingHelper().

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

Definition at line 70 of file VertexingHelper.h.

Referenced by VertexingHelper().

Definition at line 80 of file VertexingHelper.h.

use tracks inside candidates

Definition at line 79 of file VertexingHelper.h.

Referenced by VertexingHelper().

Definition at line 83 of file VertexingHelper.h.

Referenced by VertexingHelper().

Definition at line 84 of file VertexingHelper.h.

Definition at line 77 of file VertexingHelper.h.

Definition at line 76 of file VertexingHelper.h.

Referenced by VertexingHelper().