12 using namespace Eigen;
39 std::vector<float> chi2_hit;
41 std::vector<float> xy_res;
42 std::vector<float> xy_res_inv;
43 std::vector<float> z_res;
44 std::vector<float> z_res_inv;
46 for (
unsigned int i = 0; i <
hits.size(); i++) {
48 float ex = (2.0*sqrt(
hits[i].get_size(0,0))) * scale;
49 float ey = (2.0*sqrt(
hits[i].get_size(1,1))) * scale;
50 float ez = (2.0*sqrt(
hits[i].get_size(2,2))) * scale;
52 if (
hits[i].get_layer() < 0) {
58 xy_res.push_back(sqrt( ex * ex + ey * ey ));
59 xy_res_inv.push_back(1. / xy_res.back());
60 z_res.push_back( ez );
61 z_res_inv.push_back(1. / z_res.back());
64 chi2_hit.resize(
hits.size(), 0.);
66 MatrixXf
y = MatrixXf::Zero(
hits.size(), 1);
67 for (
unsigned int i = 0; i <
hits.size(); i++) {
68 y(i, 0) = (pow(
hits[i].get_x(), 2) + pow(
hits[i].get_y(), 2));
69 y(i, 0) *= xy_res_inv[i];
72 MatrixXf
X = MatrixXf::Zero(
hits.size(), 3);
73 for (
unsigned int i = 0; i <
hits.size(); i++) {
74 X(i, 0) =
hits[i].get_x();
75 X(i, 1) =
hits[i].get_y();
77 X(i, 0) *= xy_res_inv[i];
78 X(i, 1) *= xy_res_inv[i];
79 X(i, 2) *= xy_res_inv[i];
82 MatrixXf Xt = X.transpose();
84 MatrixXf prod = Xt *
X;
86 MatrixXf Xty = Xt *
y;
87 MatrixXf beta = prod.ldlt().solve(Xty);
89 float cx = beta(0, 0) * 0.5;
90 float cy = beta(1, 0) * 0.5;
91 float r = sqrt(cx * cx + cy * cy - beta(2, 0));
94 d = sqrt(cx * cx + cy * cy) -
r;
97 MatrixXf diff = y - (X * beta);
98 MatrixXf chi2 = (diff.transpose()) * diff;
103 MatrixXf
y2 = MatrixXf::Zero(
hits.size(), 1);
104 for (
unsigned int i = 0; i <
hits.size(); i++) {
105 y2(i, 0) =
hits[i].get_z();
106 y2(i, 0) *= z_res_inv[i];
109 MatrixXf
X2 = MatrixXf::Zero(
hits.size(), 2);
110 for (
unsigned int i = 0; i <
hits.size(); i++) {
111 float D = sqrt(pow(dx -
hits[i].get_x(), 2) + pow(dy -
hits[i].get_y(), 2));
114 if (0.5 *
kappa * D > 0.1) {
119 s = 2. * asin(v) /
kappa;
123 float temp2 = D * 0.5;
128 s += (3. / 20.) *
temp2;
130 s += (5. / 56.) *
temp2;
136 X2(i, 0) *= z_res_inv[i];
137 X2(i, 1) *= z_res_inv[i];
140 MatrixXf Xt2 = X2.transpose();
141 MatrixXf prod2 = Xt2 *
X2;
143 MatrixXf Xty2 = Xt2 *
y2;
144 MatrixXf beta2 = prod2.ldlt().solve(Xty2);
146 MatrixXf diff2 = y2 - (X2 * beta2);
147 MatrixXf chi2_z = (diff2.transpose()) * diff2;
150 dzdl = beta2(0, 0) / sqrt(1. + beta2(0, 0) * beta2(0, 0));
159 cx = (
d +
r) * cos(
phi);
160 cy = (
d +
r) * sin(
phi);
163 for (
unsigned int h = 0;
h <
hits.size();
h++) {
164 float dx1 =
hits[
h].get_x() - cx;
165 float dy1 =
hits[
h].get_y() - cy;
167 float dx2 =
hits[
h].get_x() + cx;
168 float dy2 =
hits[
h].get_y() + cy;
170 float xydiff1 = sqrt(dx1 * dx1 + dy1 * dy1) -
r;
171 float xydiff2 = sqrt(dx2 * dx2 + dy2 * dy2) -
r;
172 float xydiff = xydiff2;
173 if (fabs(xydiff1) < fabs(xydiff2)) {
177 float ls_xy = xy_res[
h];
180 chi2_hit[
h] += xydiff * xydiff / (ls_xy * ls_xy);
181 chi2_hit[
h] += diff2(
h, 0) * diff2(
h, 0);
183 chi2_tot += chi2_hit[
h];
186 unsigned int deg_of_freedom = 2 *
hits.size() - 5;
188 return (chi2_tot) / ((float)(deg_of_freedom));