CMS 3D CMS Logo

RZLine.h
Go to the documentation of this file.
1 #ifndef PixelTrackFitting_RZLine_H
2 #define 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  declareDynArray(float, n, r);
32  declareDynArray(float, n, z);
33  declareDynArray(float, n, errZ2);
34  for (size_t i = 0; i < n; ++i) {
35  const GlobalPoint& p = points[i];
36  r[i] = p.perp();
37  z[i] = p.z();
38  }
39 
40  float simpleCot2 = sqr((z[n - 1] - z[0]) / (r[n - 1] - r[0]));
41  for (size_t i = 0; i < n; ++i) {
42  errZ2[i] = (isBarrel[i]) ? errors[i].czz() : errors[i].rerr(points[i]) * simpleCot2;
43  }
44 
45  calculate(r, z, errZ2);
46  }
47 
51  RZLine(const std::vector<float>& r, const std::vector<float>& z, const std::vector<float>& errZ) {
52  const size_t n = errZ.size();
53  declareDynArray(float, n, errZ2);
54  for (size_t i = 0; i < n; ++i)
55  errZ2[i] = sqr(errZ[i]);
56  calculate(r, z, errZ2);
57  }
58 
62  template <size_t N>
63  RZLine(const std::array<float, N>& r, const std::array<float, N>& z, const std::array<float, N>& errZ) {
64  std::array<float, N> errZ2;
65  for (size_t i = 0; i < N; ++i)
66  errZ2[i] = sqr(errZ[i]);
67  calculate(r, z, errZ2);
68  }
69 
83  template <typename T>
84  RZLine(const T& r, const T& z, const T& errZ2, ErrZ2_tag) {
85  calculate(r, z, errZ2);
86  }
87 
88  float cotTheta() const { return cotTheta_; }
89  float intercept() const { return intercept_; }
90  float covss() const { return covss_; }
91  float covii() const { return covii_; }
92  float covsi() const { return covsi_; }
93 
94  float chi2() const { return chi2_; }
95 
96 private:
97  template <typename R, typename Z, typename E>
98  void calculate(const R& r, const Z& z, const E& errZ2) {
99  const size_t n = r.size();
100  linearFit(r.data(), z.data(), n, errZ2.data(), cotTheta_, intercept_, covss_, covii_, covsi_);
101  chi2_ = 0.f;
102  for (size_t i = 0; i < n; ++i) {
103  chi2_ += sqr(((z[i] - intercept_) - cotTheta_ * r[i])) / errZ2[i];
104  }
105  }
106 
107  template <typename T>
108  T sqr(T t) {
109  return t * t;
110  }
111 
112  float cotTheta_;
113  float intercept_;
114  float covss_;
115  float covii_;
116  float covsi_;
117  float chi2_;
118 };
119 #endif
RZLine(const P &points, const E &errors, const B &isBarrel)
Definition: RZLine.h:29
float intercept() const
Definition: RZLine.h:89
float covii_
Definition: RZLine.h:115
Definition: APVGainStruct.h:7
float covss() const
Definition: RZLine.h:90
float covsi() const
Definition: RZLine.h:92
RZLine(const std::array< float, N > &r, const std::array< float, N > &z, const std::array< float, N > &errZ)
Definition: RZLine.h:63
float chi2_
Definition: RZLine.h:117
T sqr(T t)
Definition: RZLine.h:108
float covii() const
Definition: RZLine.h:91
Definition: RZLine.h:12
RZLine(const T &r, const T &z, const T &errZ2, ErrZ2_tag)
Definition: RZLine.h:84
#define N
Definition: blowfish.cc:9
void calculate(const R &r, const Z &z, const E &errZ2)
Definition: RZLine.h:98
float covss_
Definition: RZLine.h:114
float chi2() const
Definition: RZLine.h:94
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:88
float cotTheta_
Definition: RZLine.h:112
float covsi_
Definition: RZLine.h:116
Definition: errors.py:1
#define declareDynArray(T, n, x)
Definition: DynArray.h:91
long double T
RZLine(const std::vector< float > &r, const std::vector< float > &z, const std::vector< float > &errZ)
Definition: RZLine.h:51
float intercept_
Definition: RZLine.h:113