Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:22

0001 #ifndef DataFormats_PatCandidates_interface_Vertexing_h
0002 #define DataFormats_PatCandidates_interface_Vertexing_h
0003 
0004 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0005 #include "DataFormats/VertexReco/interface/Vertex.h"
0006 #include "DataFormats/TrackReco/interface/Track.h"
0007 #include "DataFormats/Common/interface/Ptr.h"
0008 #include "DataFormats/GeometryCommonDetAlgo/interface/Measurement1DFloat.h"
0009 #include "DataFormats/GeometryCommonDetAlgo/interface/Measurement1D.h"
0010 
0011 /**
0012   \class    pat::VertexAssociation VertexAssociation.h "DataFormats/PatCandidates/interface/Vertexing.h"
0013   \brief    Analysis-level structure for vertex-related information
0014 
0015   pat::VertexAssociation holds a reference to a vertex and extended information like the distance between the object and the vertex.
0016 
0017   For convenience, pat::VertexAssociation behaves like a VertexRef, that is (*assoc) is a reco::Vertex.
0018 
0019   The original proposal is at https://hypernews.cern.ch/HyperNews/CMS/get/physTools/587.html 
0020 
0021   \author   Giovanni Petrucciani
0022 */
0023 
0024 namespace pat {
0025   class VertexAssociation {
0026   public:
0027     //! Create a null vertx association
0028     VertexAssociation() {}
0029     //! Create a vertex association given a ref to a vertex
0030     VertexAssociation(const reco::VertexRef &vertex) : vertex_(vertex) {}
0031     //! Create a vertex association given a ref to a vertex and a reference to a track object
0032     /// Note: you also have to set the distances, they can be computed by the VertexAssociation itself
0033     /// because it requires access to the magnetic field and other condition data.
0034     VertexAssociation(const reco::VertexRef &vertex, const reco::TrackBaseRef &tk) : vertex_(vertex), track_(tk) {}
0035     // --- Methods to mimick VertexRef
0036     //! Return 'true' if this is a null association (that is, no vertex)
0037     bool isNull() const { return vertex_.isNull(); }
0038     //! Return 'true' unless this is a null association (that is, no vertex)
0039     bool isNonnull() const { return vertex_.isNonnull(); }
0040     //! Return 'true' if the reco::Vertex is available in the file, false if it has been dropped.
0041     bool isAvailable() const { return vertex_.isAvailable(); }
0042     //! Return the vertex (that is, you can do "const reco::Vertex &vtx = *assoc")
0043     const reco::Vertex &operator*() const { return *operator->(); }
0044     //! Allows VertexAssociation to behave like a vertex ref  (e.g. to do "assoc->position()")
0045     const reco::Vertex *operator->() const { return vertex_.isNull() ? nullptr : vertex_.get(); }
0046     // --- Methods to get the Vertex and track
0047     //! Returns the reference to the vertex (can be a null reference)
0048     const reco::VertexRef &vertexRef() const { return vertex_; }
0049     //! Returns a pointer to the vertex, or a null pointer if there is no vertex (null association)
0050     const reco::Vertex *vertex() const { return vertex_.isNull() ? nullptr : vertex_.get(); }
0051     //! Returns 'true' if a reference to a track was stored in this VertexAssociation
0052     bool hasTrack() const { return !track_.isNull(); }
0053     //! Returns a reference to the track stored in this vertex (can be null)
0054     const reco::TrackBaseRef &trackRef() const { return track_; }
0055     //! Returns a C++ pointer to the track stored in this vertex (can be a null pointer)
0056     const reco::Track *track() const { return hasTrack() ? track_.get() : nullptr; }
0057     // --- Methods to return distances
0058     //! Distance between the object and the vertex along the Z axis, and it's error.
0059     /// Note 1: if the BeamSpot was used as Vertex, the error includes the BeamSpot spread!
0060     const Measurement1DFloat &dz() const { return dz_; }
0061     //! Distance between the object and the vertex in the transverse plane, and it's error.
0062     const Measurement1DFloat &dr() const { return dr_; }
0063     //! True if the transverse distance was computed for this VertexAssociation
0064     bool hasTransverseIP() const { return (dr_.value() != 0); }
0065     //! True if the errors on dr and dz have been set, false if they're nulls
0066     bool hasErrors() const { return (dz_.error() != 0) && (!hasTransverseIP() || dr_.error() != 0); }
0067     // ---- Methods to set distances
0068     void setDz(const Measurement1DFloat &dz) { dz_ = dz; }
0069     void setDr(const Measurement1DFloat &dr) { dr_ = dr; }
0070     void setDz(const Measurement1D &dz) { dz_ = Measurement1DFloat(dz.value(), dz.error()); }
0071     void setDr(const Measurement1D &dr) { dr_ = Measurement1DFloat(dr.value(), dr.error()); }
0072     //! Set dz and dr given the distance and the 3x3 total covariance matrix of the distance
0073     void setDistances(const AlgebraicVector3 &dist, const AlgebraicSymMatrix33 &err);
0074     //! Set dz and dr given the two points (object and vertex) and the 3x3 total covariance matrix of the distance
0075     /// The covariance matrix must already include the covariance matrix of the vertex
0076     /// 'p1', 'p2' can be anything that has methods .x(), .y(), .z() (e.g. GlobalPoint, Vertex, ...)
0077     template <typename T1, typename T2>
0078     void setDistances(const T1 &p1, const T2 &p2, const AlgebraicSymMatrix33 &err) {
0079       AlgebraicVector3 dist(p1.x() - p2.x(), p1.y() - p2.y(), p1.z() - p2.z());
0080       setDistances(dist, err);
0081     }
0082     // ---- 3D significance of the impact parameter
0083     // float signif3d()           const { return signif3d_; }
0084     // bool  hasSignif3d()        const { return signif3d_ != 0; }
0085     // void setSignif3d(float signif3d) { signif3d_ = signif3d; }
0086   private:
0087     // basic information
0088     reco::VertexRef vertex_;
0089     Measurement1DFloat dz_, dr_;
0090     // float signif3d_;
0091     // extended info
0092     reco::TrackBaseRef track_;
0093     // fixme: add refitted momentum
0094   };
0095 }  // namespace pat
0096 
0097 #endif