Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:49

0001 #ifndef DataFormats_Candidate_VertexCompositePtrCandidate_H
0002 #define DataFormats_Candidate_VertexCompositePtrCandidate_H
0003 /** \class reco::VertexCompositePtrCandidate
0004  *
0005  * A composite Candidate  with error
0006  * matrix and other vertex fix information. 
0007  *
0008  * \author Luca Lista, INFN
0009  *
0010  *
0011  */
0012 #include "DataFormats/Candidate/interface/VertexCompositePtrCandidateFwd.h"
0013 #include "DataFormats/Candidate/interface/CompositePtrCandidate.h"
0014 
0015 namespace reco {
0016   class VertexCompositePtrCandidate : public CompositePtrCandidate {
0017   public:
0018     enum { dimension4D = 4 };
0019     /// covariance error matrix (3x3)
0020     typedef math::Error<dimension4D>::type CovarianceMatrix4D;
0021     /// matix size
0022     enum { size4D = dimension4D * (dimension4D + 1) / 2 };
0023 
0024     VertexCompositePtrCandidate() : CompositePtrCandidate(), chi2_(0), ndof_(0), time_(0) {}
0025     /// constructor from values
0026     VertexCompositePtrCandidate(
0027         Charge q, const LorentzVector &p4, const Point &vtx, int pdgId = 0, int status = 0, bool integerCharge = true)
0028         : CompositePtrCandidate(q, p4, vtx, pdgId, status, integerCharge), chi2_(0), ndof_(0), time_(0) {}
0029     VertexCompositePtrCandidate(Charge q,
0030                                 const LorentzVector &p4,
0031                                 const Point &vtx,
0032                                 double time,
0033                                 int pdgId = 0,
0034                                 int status = 0,
0035                                 bool integerCharge = true)
0036         : CompositePtrCandidate(q, p4, vtx, pdgId, status, integerCharge), chi2_(0), ndof_(0), time_(time) {}
0037     /// constructor from values
0038     VertexCompositePtrCandidate(Charge q,
0039                                 const LorentzVector &p4,
0040                                 const Point &vtx,
0041                                 const CovarianceMatrix &err,
0042                                 double chi2,
0043                                 double ndof,
0044                                 int pdgId = 0,
0045                                 int status = 0,
0046                                 bool integerCharge = true);
0047     VertexCompositePtrCandidate(Charge q,
0048                                 const LorentzVector &p4,
0049                                 const Point &vtx,
0050                                 double time,
0051                                 const CovarianceMatrix4D &err,
0052                                 double chi2,
0053                                 double ndof,
0054                                 int pdgId = 0,
0055                                 int status = 0,
0056                                 bool integerCharge = true);
0057     /// constructor from values
0058     explicit VertexCompositePtrCandidate(const Candidate &p) : CompositePtrCandidate(p), chi2_(0), ndof_(0), time_(0) {}
0059     /// constructor from values
0060     explicit VertexCompositePtrCandidate(const CompositePtrCandidate &p)
0061         : CompositePtrCandidate(p), chi2_(0), ndof_(0), time_(0) {}
0062     /// destructor
0063     ~VertexCompositePtrCandidate() override;
0064     /// returns a clone of the candidate
0065     VertexCompositePtrCandidate *clone() const override;
0066 
0067     /// chi-squares
0068     double vertexChi2() const override { return chi2_; }
0069     /** Number of degrees of freedom
0070      *  Meant to be Double32_t for soft-assignment fitters: 
0071      *  tracks may contribute to the vertex with fractional weights.
0072      *  The ndof is then = to the sum of the track weights.
0073      *  see e.g. CMS NOTE-2006/032, CMS NOTE-2004/002
0074      */
0075     double vertexNdof() const override { return ndof_; }
0076     /// chi-squared divided by n.d.o.f.
0077     double vertexNormalizedChi2() const override { return chi2_ / ndof_; }
0078     /// (i, j)-th element of error matrix, i, j = 0, ... 3
0079     double vertexCovariance(int i, int j) const override { return covariance_[idx(i, j)]; }
0080     using reco::LeafCandidate::vertexCovariance;  // avoid hiding the
0081     /// return SMatrix 4D
0082     CovarianceMatrix4D vertexCovariance4D() const {
0083       CovarianceMatrix4D m;
0084       fillVertexCovariance(m);
0085       return m;
0086     }
0087 
0088     /// fill SMatrix
0089     void fillVertexCovariance(CovarianceMatrix &v) const override;
0090     /// 4D version
0091     void fillVertexCovariance(CovarianceMatrix4D &v) const;
0092 
0093     /// set chi2 and ndof
0094     void setChi2AndNdof(double chi2, double ndof) {
0095       chi2_ = chi2;
0096       ndof_ = ndof;
0097     }
0098     /// set covariance matrix
0099     void setCovariance(const CovarianceMatrix &m);
0100     /// set covariance matrix
0101     void setCovariance(const CovarianceMatrix4D &m);
0102 
0103     // set time
0104     void setTime(double time) { time_ = time; }
0105 
0106     /// the following functions are implemented to have a more consistent interface with the one of reco::Vertex
0107     typedef math::Error<dimension>::type Error;
0108     typedef math::Error<dimension4D>::type Error4D;
0109     const Point &position() const { return vertex(); }
0110     double t() const { return time_; }
0111     double tError() const { return std::sqrt(vertexCovariance(3, 3)); }
0112     Error error() const {
0113       Error m;
0114       fillVertexCovariance(m);
0115       return m;
0116     }
0117     /// return SMatrix 4D
0118     Error4D error4D() const {
0119       Error4D m;
0120       fillVertexCovariance(m);
0121       return m;
0122     }
0123 
0124   private:
0125     /// chi-sqared
0126     Double32_t chi2_;
0127     /// number of degrees of freedom
0128     Double32_t ndof_;
0129     /// covariance matrix (4x4) as vector
0130     Double32_t covariance_[size4D];
0131     /// vertex time
0132     Double32_t time_;
0133     /// position index
0134     index idx(index i, index j) const {
0135       int a = (i <= j ? i : j), b = (i <= j ? j : i);
0136       return b * (b + 1) / 2 + a;
0137     }
0138   };
0139 
0140 }  // namespace reco
0141 
0142 #endif