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() :
43  errors[i].rerr(points[i]) * simpleCot2;
44  }
45 
46  calculate(r, z, errZ2);
47  }
48 
52  RZLine(const std::vector<float> & r,
53  const std::vector<float> & z,
54  const std::vector<float> & errZ) {
55  const size_t n = errZ.size();
56  declareDynArray(float, n, errZ2);
57  for(size_t i=0; i<n; ++i) errZ2[i] = sqr(errZ[i]);
58  calculate(r, z, errZ2);
59  }
60 
64  template <size_t N>
65  RZLine(const std::array<float, N>& r,
66  const std::array<float, N>& z,
67  const std::array<float, N>& errZ) {
68  std::array<float, N> errZ2;
69  for(size_t i=0; i<N; ++i) errZ2[i] = sqr(errZ[i]);
70  calculate(r, z, errZ2);
71  }
72 
86  template <typename T>
87  RZLine (const T& r, const T& z, const T& errZ2, ErrZ2_tag) {
88  calculate(r, z, errZ2);
89  }
90 
91  float cotTheta() const { return cotTheta_; }
92  float intercept() const { return intercept_; }
93  float covss() const { return covss_; }
94  float covii() const { return covii_; }
95  float covsi() const { return covsi_; }
96 
97  float chi2() const { return chi2_; }
98 
99 private:
100  template <typename R, typename Z, typename E>
101  void calculate(const R& r, const Z& z, const E& errZ2) {
102  const size_t n = r.size();
103  linearFit(r.data(), z.data(), n, errZ2.data(), cotTheta_, intercept_, covss_, covii_, covsi_);
104  chi2_ = 0.f;
105  for(size_t i=0; i<n; ++i) {
106  chi2_ += sqr( ((z[i]-intercept_) - cotTheta_*r[i]) ) / errZ2[i];
107  }
108  }
109 
110  template <typename T>
111  T sqr(T t) { return t*t; }
112 
113  float cotTheta_;
114  float intercept_;
115  float covss_;
116  float covii_;
117  float covsi_;
118  float chi2_;
119 };
120 #endif
const double Z[kNumberCalorimeter]
RZLine(const P &points, const E &errors, const B &isBarrel)
Definition: RZLine.h:29
int i
Definition: DBlmapReader.cc:9
float covii_
Definition: RZLine.h:116
T perp() const
Definition: PV3DBase.h:72
float cotTheta() const
Definition: RZLine.h:91
float intercept() 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:65
float chi2_
Definition: RZLine.h:118
T sqr(T t)
Definition: RZLine.h:111
T z() const
Definition: PV3DBase.h:64
Definition: RZLine.h:12
RZLine(const T &r, const T &z, const T &errZ2, ErrZ2_tag)
Definition: RZLine.h:87
float covsi() const
Definition: RZLine.h:95
#define N
Definition: blowfish.cc:9
void calculate(const R &r, const Z &z, const E &errZ2)
Definition: RZLine.h:101
float covss_
Definition: RZLine.h:115
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:26
float cotTheta_
Definition: RZLine.h:113
float covsi_
Definition: RZLine.h:117
Definition: errors.py:1
#define declareDynArray(T, n, x)
Definition: DynArray.h:59
long double T
RZLine(const std::vector< float > &r, const std::vector< float > &z, const std::vector< float > &errZ)
Definition: RZLine.h:52
float chi2() const
Definition: RZLine.h:97
float intercept_
Definition: RZLine.h:114
float covii() const
Definition: RZLine.h:94
float covss() const
Definition: RZLine.h:93