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
HLT_2018_cff.points
points
Definition: HLT_2018_cff.py:20125
fftjetvertexadder_cfi.errZ
errZ
Definition: fftjetvertexadder_cfi.py:39
mps_fire.i
i
Definition: mps_fire.py:355
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
RZLine::calculate
void calculate(const R &r, const Z &z, const E &errZ2)
Definition: RZLine.h:98
RZLine::covsi
float covsi() const
Definition: RZLine.h:92
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
LinearFit.h
RZLine::sqr
T sqr(T t)
Definition: RZLine.h:108
RZLine::chi2
float chi2() const
Definition: RZLine.h:94
RZLine::covii
float covii() const
Definition: RZLine.h:91
errors
Definition: errors.py:1
RZLine::cotTheta_
float cotTheta_
Definition: RZLine.h:112
linearFit
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
DDAxes::z
RZLine::covsi_
float covsi_
Definition: RZLine.h:116
N
#define N
Definition: blowfish.cc:9
declareDynArray
#define declareDynArray(T, n, x)
Definition: DynArray.h:91
RZLine::RZLine
RZLine(const std::vector< float > &r, const std::vector< float > &z, const std::vector< float > &errZ)
Definition: RZLine.h:51
Point3DBase< float, GlobalTag >
OrderedSet.t
t
Definition: OrderedSet.py:90
RZLine::RZLine
RZLine(const P &points, const E &errors, const B &isBarrel)
Definition: RZLine.h:29
RZLine::RZLine
RZLine(const std::array< float, N > &r, const std::array< float, N > &z, const std::array< float, N > &errZ)
Definition: RZLine.h:63
PixelPluginsPhase0_cfi.isBarrel
isBarrel
Definition: PixelPluginsPhase0_cfi.py:17
RZLine::covii_
float covii_
Definition: RZLine.h:115
DOFs::Z
Definition: AlignPCLThresholdsWriter.cc:37
GlobalError.h
RZLine::cotTheta
float cotTheta() const
Definition: RZLine.h:88
DynArray.h
alignCSCRings.r
r
Definition: alignCSCRings.py:93
RZLine::covss
float covss() const
Definition: RZLine.h:90
RZLine
Definition: RZLine.h:12
TtFullHadDaughter::B
static const std::string B
Definition: TtFullHadronicEvent.h:9
RZLine::intercept_
float intercept_
Definition: RZLine.h:113
T
long double T
Definition: Basic3DVectorLD.h:48
RZLine::RZLine
RZLine(const T &r, const T &z, const T &errZ2, ErrZ2_tag)
Definition: RZLine.h:84
RZLine::intercept
float intercept() const
Definition: RZLine.h:89
RZLine::ErrZ2_tag
Definition: RZLine.h:14
RZLine::chi2_
float chi2_
Definition: RZLine.h:117
P
std::pair< OmniClusterRef, TrackingParticleRef > P
Definition: BDHadronTrackMonitoringAnalyzer.cc:202
RZLine::covss_
float covss_
Definition: RZLine.h:114
dttmaxenums::R
Definition: DTTMax.h:29
GlobalPoint.h