File indexing completed on 2024-04-06 12:05:23
0001 #ifndef VertexReco_Vertex_h
0002 #define VertexReco_Vertex_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <Rtypes.h>
0021 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0022 #include "DataFormats/Math/interface/Error.h"
0023 #include "DataFormats/Math/interface/Point3D.h"
0024 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0025 #include "DataFormats/TrackReco/interface/Track.h"
0026 #include "DataFormats/Common/interface/RefToBase.h"
0027 #include <Math/GenVector/PxPyPzE4D.h>
0028 #include <Math/GenVector/PxPyPzM4D.h>
0029 #include "DataFormats/Math/interface/LorentzVector.h"
0030
0031 namespace reco {
0032
0033 class Track;
0034
0035 class Vertex {
0036 public:
0037
0038 typedef std::vector<TrackBaseRef>::const_iterator trackRef_iterator;
0039
0040 typedef math::XYZPoint Point;
0041
0042 constexpr static int dimension = 3;
0043 constexpr static int dimension4D = 4;
0044
0045 typedef math::Error<dimension>::type Error;
0046
0047 typedef math::Error<dimension>::type CovarianceMatrix;
0048
0049 typedef math::Error<dimension4D>::type Error4D;
0050
0051 typedef math::Error<dimension4D>::type CovarianceMatrix4D;
0052
0053 constexpr static int size = dimension * (dimension + 1) / 2, size4D = (dimension4D) * (dimension4D + 1) / 2;
0054
0055 typedef unsigned int index;
0056
0057
0058
0059 Vertex() : chi2_(0.0), ndof_(0), position_(0., 0., 0.), time_(0.) {
0060 validity_ = false;
0061 for (int i = 0; i < size4D; ++i)
0062 covariance_[i] = 0.;
0063 }
0064
0065 Vertex(const Point &, const Error &);
0066
0067 Vertex(const Point &, const Error4D &, double);
0068
0069 Vertex(const Point &, const Error &, double chi2, double ndof, size_t size);
0070
0071 Vertex(const Point &, const Error4D &, double time, double chi2, double ndof, size_t size);
0072
0073 bool isValid() const { return validity_; }
0074
0075
0076
0077 bool isFake() const { return (chi2_ == 0 && ndof_ == 0 && tracks_.empty()); }
0078
0079 void reserve(int size, bool refitAsWell = false) {
0080 tracks_.reserve(size);
0081 if (refitAsWell)
0082 refittedTracks_.reserve(size);
0083 weights_.reserve(size);
0084 }
0085
0086 template <typename Ref>
0087 void add(Ref const &r, float w = 1.0) {
0088 tracks_.emplace_back(r);
0089 weights_.emplace_back(w * 255.f);
0090 }
0091
0092 void add(const TrackBaseRef &r, const Track &refTrack, float w = 1.0);
0093 void removeTracks();
0094
0095
0096 template <typename TREF>
0097 float trackWeight(const TREF &r) const {
0098 int i = 0;
0099 for (auto const &t : tracks_) {
0100 if ((r.id() == t.id()) && (t.key() == r.key()))
0101 return weights_[i] / 255.f;
0102 ++i;
0103 }
0104 return 0;
0105 }
0106
0107 auto const &tracks() const { return tracks_; }
0108
0109 trackRef_iterator tracks_begin() const { return tracks_.begin(); }
0110
0111 trackRef_iterator tracks_end() const { return tracks_.end(); }
0112
0113 size_t tracksSize() const { return tracks_.size(); }
0114
0115 const TrackBaseRef &trackRefAt(size_t idx) const { return tracks_[idx]; }
0116
0117 double chi2() const { return chi2_; }
0118
0119
0120
0121
0122
0123
0124 double ndof() const { return ndof_; }
0125
0126 double normalizedChi2() const { return ndof_ != 0 ? chi2_ / ndof_ : chi2_ * 1e6; }
0127
0128 const Point &position() const { return position_; }
0129
0130 double x() const { return position_.X(); }
0131
0132 double y() const { return position_.Y(); }
0133
0134 double z() const { return position_.Z(); }
0135
0136 double t() const { return time_; }
0137
0138 double xError() const { return sqrt(covariance(0, 0)); }
0139
0140 double yError() const { return sqrt(covariance(1, 1)); }
0141
0142 double zError() const { return sqrt(covariance(2, 2)); }
0143
0144 double tError() const { return sqrt(covariance(3, 3)); }
0145
0146
0147
0148
0149 double covariance(int i, int j) const { return covariance_[idx(i, j)]; }
0150
0151 CovarianceMatrix covariance() const {
0152 Error m;
0153 fill(m);
0154 return m;
0155 }
0156
0157 CovarianceMatrix4D covariance4D() const {
0158 Error4D m;
0159 fill(m);
0160 return m;
0161 }
0162
0163
0164 Error error() const {
0165 Error m;
0166 fill(m);
0167 return m;
0168 }
0169
0170 Error4D error4D() const {
0171 Error4D m;
0172 fill(m);
0173 return m;
0174 }
0175
0176
0177 void fill(CovarianceMatrix &v) const;
0178
0179 void fill(CovarianceMatrix4D &v) const;
0180
0181
0182 bool hasRefittedTracks() const { return !refittedTracks_.empty(); }
0183
0184
0185
0186 TrackBaseRef originalTrack(const Track &refTrack) const;
0187
0188
0189
0190 Track refittedTrack(const TrackBaseRef &track) const;
0191
0192
0193
0194 Track refittedTrack(const TrackRef &track) const;
0195
0196
0197 const std::vector<Track> &refittedTracks() const { return refittedTracks_; }
0198
0199
0200 math::XYZTLorentzVectorD p4(float mass = 0.13957018, float minWeight = 0.5) const;
0201
0202
0203 unsigned int nTracks(float minWeight = 0.5) const;
0204
0205 class TrackEqual {
0206 public:
0207 TrackEqual(const Track &t) : track_(t) {}
0208 bool operator()(const Track &t) const { return t.pt() == track_.pt(); }
0209
0210 private:
0211 const Track &track_;
0212 };
0213
0214 private:
0215
0216 float chi2_;
0217
0218 float ndof_;
0219
0220 Point position_;
0221
0222 float covariance_[size4D];
0223
0224 std::vector<TrackBaseRef> tracks_;
0225
0226 std::vector<Track> refittedTracks_;
0227 std::vector<uint8_t> weights_;
0228
0229 bool validity_;
0230 double time_;
0231
0232
0233 index idx(index i, index j) const {
0234 int a = (i <= j ? i : j), b = (i <= j ? j : i);
0235 return b * (b + 1) / 2 + a;
0236 }
0237 };
0238
0239 }
0240
0241 #endif