28 float radius = fitpars[0];
29 float x0 = fitpars[1];
30 float y0 = fitpars[2];
31 float zslope = fitpars[3];
32 float z0 = fitpars[4];
37 float pca_circle_radius = pca_circle.norm();
38 float pca_z = pca_circle_radius * zslope + z0;
43 float angle_pca = atan2(pca_circle(1) - y0, pca_circle(0) - x0);
45 float d_angle = 0.005;
46 float newx = radius * cos(angle_pca + d_angle) +
x0;
47 float newy = radius * sin(angle_pca + d_angle) + y0;
48 float newz = sqrt(newx * newx + newy * newy) * zslope + z0;
52 Acts::Vector3 tangent = (second_point_pca - pca) / (second_point_pca - pca).norm();
59 Acts::Vector3 final_pca = pca + ((global - pca).dot(tangent)) * tangent;
61 auto line = std::make_pair(final_pca, tangent);
74 for (
const auto& [
x,
y] : positions)
92 for (
auto& [
x,
y] : positions)
94 double Xi =
x - meanX;
95 double Yi =
y - meanY;
114 const double Mz = Mxx + Myy;
115 const double Cov_xy = Mxx * Myy - Mxy * Mxy;
116 const double Var_z = Mzz - Mz * Mz;
117 const double A3 = 4 * Mz;
118 const double A2 = -3 * Mz * Mz - Mzz;
119 const double A1 = Var_z * Mz + 4 * Cov_xy * Mz - Mxz * Mxz - Myz * Myz;
120 const double A0 = Mxz * (Mxz * Myy - Myz * Mxy) + Myz * (Myz * Mxx - Mxz * Mxy) - Var_z * Cov_xy;
121 const double A22 = A2 + A2;
122 const double A33 = A3 + A3 + A3;
127 static constexpr
int iter_max = 99;
132 for (
int iter = 0; iter < iter_max; ++iter)
134 const double Dy = A1 + x * (A22 + A33 *
x);
135 const double xnew = x - y / Dy;
136 if ((xnew == x) || (!std::isfinite(xnew)))
break;
138 const double ynew = A0 + xnew * (A1 + xnew * (A2 + xnew * A3));
139 if (std::abs(ynew) >= std::abs(y))
break;
146 const double DET =
square(x) - x * Mz + Cov_xy;
147 const double Xcenter = (Mxz * (Myy -
x) - Myz * Mxy) / DET / 2;
148 const double Ycenter = (Myz * (Mxx -
x) - Mxz * Mxy) / DET / 2;
151 double X0 = Xcenter + meanX;
152 double Y0 = Ycenter + meanY;
153 double R = std::sqrt(
square(Xcenter) +
square(Ycenter) + Mz);
161 for (
const auto&
position : positions)
177 for (
const auto& [
r,
z] : positions)
181 x2sum = x2sum +
square(r);
182 y2sum = y2sum +
square(z);
183 xysum = xysum + r *
z;
186 const auto npts = positions.size();
187 const double denominator = (x2sum * npts -
square(xsum));
188 const double a = (xysum * npts - xsum * ysum) / denominator;
189 const double b = (x2sum * ysum - xsum * xysum) / denominator;
196 const double denominatoryx = (y2sum * npts -
square(ysum));
197 const double inva = (xysum * npts - xsum * ysum) / denominatoryx;
198 const double invb = (y2sum * xsum - ysum * xysum) / denominatoryx;
202 float suminvresid = 0;
203 for (
const auto& [
r,
z] : positions)
205 sumresid +=
square(
z - (a *
r + b));
206 suminvresid +=
square(
r - (inva *
z + invb));
209 if (sumresid < suminvresid)
222 for (
const auto&
position : positions)
234 const double a = 1.0 +
square(x2 / y2);
235 const double b = -D * x2 /
square(y2);
239 const double sqdelta = std::sqrt(delta);
241 const double xplus = (-b + sqdelta) / (2. * a);
242 const double xminus = (-b - sqdelta) / (2. * a);
244 const double yplus = -(2 * x2 * xplus - D) / (2. * y2);
245 const double yminus = -(2 * x2 * xminus - D) / (2. * y2);
252 const double& dca_cut,
255 std::vector<Acts::Vector3>& global_vec,
256 std::vector<TrkrDefs::cluskey>& cluskey_vec,
257 const unsigned int& startLayer,
258 const unsigned int& endLayer)
260 float slope = std::get<0>(fitpars);
264 std::set<TrkrDefs::cluskey> keys_to_add;
294 for (
const auto& det : detectors)
305 for (
auto clusIter = range.first; clusIter != range.second; ++clusIter)
323 if (global.y() < 0) y *= -1;
330 float perpSlope = -1 / slope;
331 float perpIntercept = y - perpSlope *
x;
334 float pcax = (perpIntercept -
intercept) / (slope - perpSlope);
338 float dcax = pcax -
x;
339 float dcay = pcay -
y;
344 keys_to_add.insert(cluskey);
350 for (
auto& key : keys_to_add)
352 cluskey_vec.push_back(key);
355 global_vec.push_back(global);
367 std::vector<Acts::Vector3>& global_vec,
368 std::vector<TrkrDefs::cluskey>& cluskey_vec,
369 unsigned int startLayer,
370 unsigned int endLayer)
375 unsigned int nclusters = 0;
378 std::vector<float> best_layer_dca;
379 best_layer_dca.assign(endLayer + 1, 999.0);
380 std::vector<TrkrDefs::cluskey> best_layer_cluskey;
381 best_layer_cluskey.assign(endLayer + 1, 0);
412 for (
const auto& det : detectors)
423 for (
auto clusIter = range.first; clusIter != range.second; ++clusIter)
433 float dca = (pca - global).
norm();
438 dca = pca_xy_residual.norm();
440 if (dca < best_layer_dca[layer])
451 if (best_layer_cluskey[
layer] == 0)
455 if (best_layer_dca[
layer] < dca_cut)
457 cluskey_vec.push_back(best_layer_cluskey[
layer]);
458 auto clus = _cluster_map->
findCluster(best_layer_cluskey[layer]);
460 global_vec.push_back(global);
475 float radius = fitpars[0];
476 float x0 = fitpars[1];
477 float y0 = fitpars[2];
478 float zslope = fitpars[3];
479 float z0 = fitpars[4];
484 float pca_circle_radius = pca_circle.norm();
485 float pca_z = pca_circle_radius * zslope + z0;
490 float projection = 0.25;
491 Acts::Vector3 second_point = pca + projection * pca / pca.norm();
493 float second_point_pca_z = pca_circle_radius * zslope + z0;
494 Acts::Vector3 second_point_pca(second_point_pca_circle(0), second_point_pca_circle(1), second_point_pca_z);
497 Acts::Vector3 tangent = (second_point_pca - pca) / (second_point_pca - pca).norm();
522 std::vector<TrkrDefs::cluskey> cluskey_vec)
524 std::vector<float> fitpars;
527 if (global_vec.size() < 3)
534 std::vector<Acts::Vector3> global_vec_noINTT;
535 for (
unsigned int ivec = 0; ivec < global_vec.size(); ++ivec)
541 global_vec_noINTT.push_back(global_vec[ivec]);
545 if (global_vec_noINTT.size() < 3)
551 fitpars.push_back(std::get<0>(circle_fit_pars));
552 fitpars.push_back(std::get<1>(circle_fit_pars));
553 fitpars.push_back(std::get<2>(circle_fit_pars));
554 fitpars.push_back(std::get<0>(line_fit_pars));
555 fitpars.push_back(std::get<1>(line_fit_pars));
563 std::vector<Acts::Vector3>& global_vec,
564 std::vector<TrkrDefs::cluskey>& cluskey_vec)
566 for (
unsigned int iclus = 0; iclus < cluskey_vec.size(); ++iclus)
568 auto key = cluskey_vec[iclus];
572 std::cout <<
"Failed to get cluster with key " << key << std::endl;
589 global_vec.push_back(global);
601 Acts::Vector3 pca = posref + ((global - posref).dot(tangent)) * tangent;
616 std::vector<double> residuals;
619 std::back_inserter(residuals), [slope,
intercept](
const std::pair<double, double>&
point)
629 return std::abs(a*r+b*z+c)/sqrt(
square(a)+
square(b)); });
635 std::vector<double> residuals;
637 std::back_inserter(residuals), [
R,
X0,
Y0](
const std::pair<double, double>&
point)