9#include <tracking/trackFindingVXD/trackQualityEstimators/QualityEstimatorCircleFit.h>
10#include <tracking/trackFindingVXD/utilities/CalcCurvatureSignum.h>
12#include <framework/logging/Logger.h>
21 if (measurements.size() < 4) {
22 if (measurements.size() == 3)
return 0.2;
31 double stopper = 0.000000001;
32 double meanX = 0, meanY = 0, meanX2 = 0, meanY2 = 0, meanR2 = 0, meanR4 = 0, meanXR2 = 0, meanYR2 = 0, meanXY = 0;
33 double sumWeights = 0, divisor;
34 double tuningParameter = 1.;
38 double weight = 1. / (
sqrt(hit->getPositionError().X() * hit->getPositionError().X() + hit->getPositionError().Y() *
39 hit->getPositionError().Y()) * tuningParameter);
41 if (std::isnan(weight) or std::isinf(weight)) {
42 B2ERROR(
"QualityEstimators::circleFit, chosen sigma is 'nan': " << weight <<
", setting arbitrary error: "
43 << stopper <<
")"); weight = stopper;
45 double x = hit->getPosition().X();
46 double y = hit->getPosition().Y();
52 meanXY += x * y * weight;
53 meanX2 += x2 * weight;
54 meanY2 += y2 * weight;
55 meanXR2 += x * r2 * weight;
56 meanYR2 += y * r2 * weight;
57 meanR2 += r2 * weight;
58 meanR4 += r2 * r2 * weight;
60 divisor = 1. / sumWeights;
72 double covXX = meanX2 - meanX * meanX;
73 double covXY = meanXY - meanX * meanY;
74 double covYY = meanY2 - meanY * meanY;
75 double covXR2 = meanXR2 - meanX * meanR2;
76 double covYR2 = meanYR2 - meanY * meanR2;
77 double covR2R2 = meanR4 - meanR2 * meanR2;
84 double q1 = covR2R2 * covXY - covXR2 * covYR2;
85 double q2 = covR2R2 * (covXX - covYY) - covXR2 * covXR2 + covYR2 * covYR2;
88 double pocaPhi = 0.5 * atan2(2. * q1, q2);
90 double sinPhi = sin(pocaPhi);
91 double cosPhi = cos(pocaPhi);
92 double kappa = (sinPhi * covXR2 - cosPhi * covYR2) / covR2R2;
93 double delta = -kappa * meanR2 + sinPhi * meanX - cosPhi * meanY;
94 double rootTerm =
sqrt(1. - 4.*delta * kappa);
96 double curvature = 2.*kappa / (rootTerm);
97 double pocaD = 2.*delta / (1. + rootTerm);
100 if ((curvature < 0 && clockwise) || (curvature > 0 && !clockwise)) {
102 curvature = -curvature;
106 double radius = 1. / curvature;
107 double absRadius = fabs(radius);
108 double pt =
calcPt(absRadius);
114 double innermostHitTheta = 0.;
115 double innermostHitRadiusSquared = 100000000;
117 if (hit->getPosition().Perp2() < innermostHitRadiusSquared) {
118 innermostHitRadiusSquared = hit->getPosition().Perp2();
119 innermostHitTheta = hit->getPosition().Theta();
123 double pz = (innermostHitTheta <= 1e-6 ? 0 : pt / tan(innermostHitTheta));
128 double chi2 = sumWeights * (1. + curvature * pocaD) * (1. + curvature * pocaD)
129 * (sinPhi * sinPhi * covXX - 2.*sinPhi * cosPhi * covXY + cosPhi * cosPhi * covYY - kappa * kappa * covR2R2);
133 return TMath::Prob(chi2, measurements.size() - 3);
QualityEstimationResults m_results
Result of the quality estimation This is stored as a member variable, because some values may be calc...
double calcPt(double const radius) const
Returns a value for the transverse momentum in GeV calculated from a provided radius.
virtual double estimateQuality(std::vector< SpacePoint const * > const &measurements) final
Minimal implementation of the quality estimation Calculates quality indicator in range [0,...
SpacePoint typically is build from 1 PXDCluster or 1-2 SVDClusters.
B2Vector3< double > B2Vector3D
typedef for common usage with double
double sqrt(double a)
sqrt for double
short calcCurvatureSignum(std::vector< SpacePoint const * > const &measurements)
Calculate curvature based on triplets of measurements.
Abstract base class for different kinds of events.
std::optional< double > pt
transverse momentum estimate from the QE
std::optional< short > curvatureSign
direction of curvature as obtained by the QE
std::optional< double > pocaD
distance to the z-axis of the POCA
std::optional< double > chiSquared
chi squared value obtained by the fit of the QE
std::optional< B2Vector3D > p
momentum vector estimate from the QE
std::optional< double > pmag
momentum magnitute estimate from the QE