1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
#ifndef GlobalErrorType_H
#define GlobalErrorType_H
#include "DataFormats/GeometryCommonDetAlgo/interface/DeepCopyPointer.h"
#include "DataFormats/Math/interface/AlgebraicROOTObjects.h"
#include "DataFormats/GeometryVector/interface/GlobalPoint.h"
//
// Exceptions
//
#include "FWCore/Utilities/interface/Exception.h"
/**
* Templated class representing a symmetric 3*3 matrix describing, according
* to the ErrorWeightType tag, a (cartesian) covariance matrix or the weight
* matrix (the inverse of the covariance matrix).
* \li To have a covariance matrix, the ErrorMatrixTag has to be used, and a
* typedef is available as GlobalError
* \li To have a weight matrix, the WeightMatrixTag has to be used, and a
* typedef is available as Globalweight
*
* The typedefs should be used in the code.
*/
template <class T, class ErrorWeightType>
class GlobalErrorBase {
public:
/// Tag to request a null error matrix
class NullMatrix {};
/**
* Default constructor, creating a null 3*3 matrix (all values are 0)
*/
GlobalErrorBase() {}
/**
* Obsolete Constructor that allocates a null GlobalErrorBase (it does not create the error matrix at all)
*/
GlobalErrorBase(const NullMatrix&) {}
/**
* Constructor.
* The symmetric matrix stored as a lower triangular matrix
*/
GlobalErrorBase(T c11, T c21, T c22, T c31, T c32, T c33) {
theCartesianError(0, 0) = c11;
theCartesianError(1, 0) = c21;
theCartesianError(1, 1) = c22;
theCartesianError(2, 0) = c31;
theCartesianError(2, 1) = c32;
theCartesianError(2, 2) = c33;
theCartesianError(3, 0) = 0.;
theCartesianError(3, 1) = 0.;
theCartesianError(3, 2) = 0.;
theCartesianError(3, 3) = 0.;
}
/**
* Constructor.
* The symmetric matrix stored as a lower triangular matrix (4D)
*/
GlobalErrorBase(T c11, T c21, T c22, T c31, T c32, T c33, T c41, T c42, T c43, T c44) {
theCartesianError(0, 0) = c11;
theCartesianError(1, 0) = c21;
theCartesianError(1, 1) = c22;
theCartesianError(2, 0) = c31;
theCartesianError(2, 1) = c32;
theCartesianError(2, 2) = c33;
theCartesianError(3, 0) = c41;
theCartesianError(3, 1) = c42;
theCartesianError(3, 2) = c43;
theCartesianError(3, 3) = c44;
}
/**
* Constructor from SymMatrix. The original matrix has to be a 3*3 matrix.
*/
GlobalErrorBase(const AlgebraicSymMatrix33& err) {
theCartesianError(0, 0) = err(0, 0);
theCartesianError(1, 0) = err(1, 0);
theCartesianError(1, 1) = err(1, 1);
theCartesianError(2, 0) = err(2, 0);
theCartesianError(2, 1) = err(2, 1);
theCartesianError(2, 2) = err(2, 2);
theCartesianError(3, 0) = 0.;
theCartesianError(3, 1) = 0.;
theCartesianError(3, 2) = 0.;
theCartesianError(3, 3) = 0.;
}
/**
* Constructor from SymMatrix. The original matrix has to be a 4*4 matrix.
*/
GlobalErrorBase(const AlgebraicSymMatrix44& err) : theCartesianError(err) {}
~GlobalErrorBase() {}
T cxx() const { return theCartesianError(0, 0); }
T cyx() const { return theCartesianError(1, 0); }
T cyy() const { return theCartesianError(1, 1); }
T czx() const { return theCartesianError(2, 0); }
T czy() const { return theCartesianError(2, 1); }
T czz() const { return theCartesianError(2, 2); }
T ctx() const { return theCartesianError(3, 0); }
T cty() const { return theCartesianError(3, 1); }
T ctz() const { return theCartesianError(3, 2); }
T ctt() const { return theCartesianError(3, 3); }
/**
* Access method to the matrix,
* /return The SymMatrix
*/
const AlgebraicSymMatrix33 matrix() const {
AlgebraicSymMatrix33 out;
out(0, 0) = theCartesianError(0, 0);
out(1, 0) = theCartesianError(1, 0);
out(1, 1) = theCartesianError(1, 1);
out(2, 0) = theCartesianError(2, 0);
out(2, 1) = theCartesianError(2, 1);
out(2, 2) = theCartesianError(2, 2);
return out;
}
/**
* Access method to the matrix,
* /return The SymMatrix 4x4
*/
const AlgebraicSymMatrix44& matrix4D() const { return theCartesianError; }
T rerr(const GlobalPoint& aPoint) const {
T r2 = aPoint.perp2();
T x2 = aPoint.x() * aPoint.x();
T y2 = aPoint.y() * aPoint.y();
T xy = aPoint.x() * aPoint.y();
if (r2 != 0)
return std::max<T>(0, (1. / r2) * (x2 * cxx() + 2. * xy * cyx() + y2 * cyy()));
else
return 0.5 * (cxx() + cyy());
}
T phierr(const GlobalPoint& aPoint) const {
T r2 = aPoint.perp2();
T x2 = aPoint.x() * aPoint.x();
T y2 = aPoint.y() * aPoint.y();
T xy = aPoint.x() * aPoint.y();
if (r2 != 0)
return std::max<T>(0, (1. / (r2 * r2)) * (y2 * cxx() - 2. * xy * cyx() + x2 * cyy()));
else
return 0;
}
GlobalErrorBase operator+(const GlobalErrorBase& err) const {
return GlobalErrorBase(theCartesianError + err.theCartesianError);
}
GlobalErrorBase operator-(const GlobalErrorBase& err) const {
return GlobalErrorBase(theCartesianError - err.theCartesianError);
}
private:
AlgebraicSymMatrix44 theCartesianError;
};
#endif
|