CMS 3D CMS Logo

RZLine.h
Go to the documentation of this file.
1 #ifndef RecoTracker_PixelTrackFitting_RZLine_h
2 #define RecoTracker_PixelTrackFitting_RZLine_h
3 
7 
9 
10 #include <vector>
11 
12 class RZLine {
13 public:
14  struct ErrZ2_tag {};
15 
28  template <typename P, typename E, typename B>
29  RZLine(const P& points, const E& errors, const B& isBarrel) {
30  const size_t n = points.size();
31  const size_t nSafe = n > 0 ? n : 1;
32  float r[nSafe];
33  float z[nSafe];
34  float errZ2[nSafe];
35  for (size_t i = 0; i < n; ++i) {
36  const GlobalPoint& p = points[i];
37  r[i] = p.perp();
38  z[i] = p.z();
39  }
40 
41  float simpleCot2 = n > 1 ? sqr((z[n - 1] - z[0]) / (r[n - 1] - r[0])) : 0.f;
42  for (size_t i = 0; i < n; ++i) {
43  errZ2[i] = (isBarrel[i]) ? errors[i].czz() : errors[i].rerr(points[i]) * simpleCot2;
44  }
45 
46  calculate(r, z, errZ2, n);
47  }
48 
52  RZLine(const std::vector<float>& r, const std::vector<float>& z, const std::vector<float>& errZ) {
53  const size_t n = errZ.size();
54  float errZ2[n > 0 ? n : n + 1];
55  for (size_t i = 0; i < n; ++i)
56  errZ2[i] = sqr(errZ[i]);
57  calculate(r.data(), z.data(), errZ2, n);
58  }
59 
63  template <size_t N>
64  RZLine(const std::array<float, N>& r, const std::array<float, N>& z, const std::array<float, N>& errZ) {
65  std::array<float, N> errZ2;
66  for (size_t i = 0; i < N; ++i)
67  errZ2[i] = sqr(errZ[i]);
68  calculate(r.data(), z.data(), errZ2.data(), N);
69  }
70 
84  template <typename T>
85  RZLine(const T& r, const T& z, const T& errZ2, ErrZ2_tag) {
86  calculate(r.data(), z.data(), errZ2.data(), r.size());
87  }
88 
89  float cotTheta() const { return cotTheta_; }
90  float intercept() const { return intercept_; }
91  float covss() const { return covss_; }
92  float covii() const { return covii_; }
93  float covsi() const { return covsi_; }
94 
95  float chi2() const { return chi2_; }
96 
97 private:
98  template <typename T>
99  void calculate(const T* r, const T* z, const T* errZ2, size_t n) {
100  //Have 0 and 1 cases return same value
101  if (n < 2) [[unlikely]] {
102  n = 0;
103  }
105  chi2_ = 0.f;
106  for (size_t i = 0; i < n; ++i) {
107  chi2_ += sqr(((z[i] - intercept_) - cotTheta_ * r[i])) / errZ2[i];
108  }
109  }
110 
111  template <typename T>
112  static constexpr T sqr(T t) {
113  return t * t;
114  }
115 
116  float cotTheta_;
117  float intercept_;
118  float covss_;
119  float covii_;
120  float covsi_;
121  float chi2_;
122 };
123 #endif
RZLine(const P &points, const E &errors, const B &isBarrel)
Definition: RZLine.h:29
float intercept() const
Definition: RZLine.h:90
float covii_
Definition: RZLine.h:119
Definition: APVGainStruct.h:7
float covss() const
Definition: RZLine.h:91
float covsi() const
Definition: RZLine.h:93
RZLine(const std::array< float, N > &r, const std::array< float, N > &z, const std::array< float, N > &errZ)
Definition: RZLine.h:64
float chi2_
Definition: RZLine.h:121
static constexpr T sqr(T t)
Definition: RZLine.h:112
float covii() const
Definition: RZLine.h:92
Definition: RZLine.h:12
RZLine(const T &r, const T &z, const T &errZ2, ErrZ2_tag)
Definition: RZLine.h:85
#define N
Definition: blowfish.cc:9
float covss_
Definition: RZLine.h:118
void calculate(const T *r, const T *z, const T *errZ2, size_t n)
Definition: RZLine.h:99
float chi2() const
Definition: RZLine.h:95
std::pair< OmniClusterRef, TrackingParticleRef > P
void linearFit(T const *__restrict__ x, T const *__restrict__ y, int ndat, T const *__restrict__ sigy2, T &slope, T &intercept, T &covss, T &covii, T &covsi)
Definition: LinearFit.h:29
float cotTheta() const
Definition: RZLine.h:89
float cotTheta_
Definition: RZLine.h:116
float covsi_
Definition: RZLine.h:120
Definition: errors.py:1
long double T
RZLine(const std::vector< float > &r, const std::vector< float > &z, const std::vector< float > &errZ)
Definition: RZLine.h:52
float intercept_
Definition: RZLine.h:117