Belle II Software development
CDCRobustSZFitter Class Reference

Utility class implementing robust versions of linear sz trajectory line fits. More...

#include <CDCRobustSZFitter.h>

Static Public Member Functions

static TrackingUtilities::CDCTrajectorySZ fitUsingSimplifiedTheilSen (const CDCSZObservations &szObservations)
 Fit a linear sz trajectory to the reconstructed stereo segment.
 
static TrackingUtilities::CDCTrajectorySZ fitTheilSen (const CDCSZObservations &szObservations)
 Implements the original Theil-Sen line fit algorithm.
 
static TrackingUtilities::CDCTrajectorySZ fitWeightedTheilSen (const CDCSZObservations &szObservations)
 Implements the weighted Theil-Sen line fit algorithm.
 

Static Private Member Functions

static double getMedianZ0 (const CDCSZObservations &szObservations, double tanLambda)
 Compute the median z0 intercept from the given observations and an estimated slope.
 

Detailed Description

Utility class implementing robust versions of linear sz trajectory line fits.

Definition at line 23 of file CDCRobustSZFitter.h.

Member Function Documentation

◆ fitTheilSen()

CDCTrajectorySZ fitTheilSen ( const CDCSZObservations & szObservations)
static

Implements the original Theil-Sen line fit algorithm.

Does not estimate the covariances of the fit parameters.

Definition at line 58 of file CDCRobustSZFitter.cc.

59{
60 std::vector<double> tanLambdas;
61 tanLambdas.reserve(szObservations.size() * (szObservations.size() - 1) / 2);
62 for (unsigned int i = 0; i < szObservations.size(); i++) {
63 for (unsigned int j = i + 1; j < szObservations.size(); j++) {
64 double s1 = szObservations.getS(i);
65 double s2 = szObservations.getS(j);
66 if (s1 == s2) continue;
67 double z1 = szObservations.getZ(i);
68 double z2 = szObservations.getZ(j);
69 tanLambdas.push_back((z2 - z1) / (s2 - s1));
70 }
71 }
72
73 const double tanLambda = median(std::move(tanLambdas));
74 const double z0 = getMedianZ0(szObservations, tanLambda);
75
76 CDCTrajectorySZ trajectorySZ(tanLambda, z0);
77 trajectorySZ.setNDF(szObservations.size());
78 return trajectorySZ;
79}
static double getMedianZ0(const CDCSZObservations &szObservations, double tanLambda)
Compute the median z0 intercept from the given observations and an estimated slope.
double getZ(int iObservation) const
Getter for the z value of the observation at the given index.
std::size_t size() const
Returns the number of observations stored.
double getS(int iObservation) const
Getter for the arc length value of the observation at the given index.

◆ fitUsingSimplifiedTheilSen()

CDCTrajectorySZ fitUsingSimplifiedTheilSen ( const CDCSZObservations & szObservations)
static

Fit a linear sz trajectory to the reconstructed stereo segment.

It uses the normal fitting algorithm but does so multiple times: In every iteration, one hit is excluded from the observation set and the rest is fitted. In the end, the mean over the fitting parameters is built and returned.

Does not estimate the covariances of the fit parameters.

TODO:

  • Use the median.
  • Use RANSAC instead of Theil-Sen.
  • Think about the parameters better.

Definition at line 23 of file CDCRobustSZFitter.cc.

24{
25 // This seems to be some other algorithm
26
27
28 CDCTrajectorySZ trajectorySZ;
29 CDCSZFitter szFitter;
30
31 if (observationsSZ.size() > 4) {
32 CDCSZObservations observationsSZFiltered;
33
34 double meanTanLambda = 0;
35 double meanStartZ = 0;
36
37 for (unsigned int i = 0; i < observationsSZ.size(); i++) {
38 for (unsigned int j = 0; j < observationsSZ.size(); j++) {
39 if (i != j) {
40 observationsSZFiltered.fill(observationsSZ.getS(j),
41 observationsSZ.getZ(j),
42 observationsSZ.getWeight(j));
43 }
44 } // for j
45
46 szFitter.update(trajectorySZ, observationsSZFiltered);
47 meanTanLambda += trajectorySZ.getTanLambda();
48 meanStartZ += trajectorySZ.getZ0();
49 } // for i
50
51 return CDCTrajectorySZ(meanTanLambda / observationsSZ.size(),
52 meanStartZ / observationsSZ.size());
53 } else {
55 }
56}
static void update(const TrackingUtilities::CDCSegmentPair &segmentPair)
Updates the trajectory of the axial stereo segment pair inplace.
std::size_t fill(double s, double z, double weight=1.0)
Appends the observed position.
static CDCTrajectorySZ basicAssumption()
Constructs a basic assumption, what the z0 start position and the sz slope are, including some broad ...
double getTanLambda() const
Getter for the slope over the travel distance coordinate.
double getZ0() const
Getter for the z coordinate at zero travel distance.

◆ fitWeightedTheilSen()

CDCTrajectorySZ fitWeightedTheilSen ( const CDCSZObservations & szObservations)
static

Implements the weighted Theil-Sen line fit algorithm.

Does not estimate the covariances of the fit parameters.

Definition at line 81 of file CDCRobustSZFitter.cc.

82{
83 std::vector<WithWeight<double> > weightedTanLambdas;
84 Weight totalWeight = 0;
85 weightedTanLambdas.reserve(szObservations.size() * (szObservations.size() - 1) / 2);
86 for (unsigned int i = 0; i < szObservations.size(); i++) {
87 for (unsigned int j = i + 1; j < szObservations.size(); j++) {
88 double s1 = szObservations.getS(i);
89 double s2 = szObservations.getS(j);
90 if (s1 == s2) continue;
91 double z1 = szObservations.getZ(i);
92 double z2 = szObservations.getZ(j);
93
94 double w1 = szObservations.getWeight(i);
95 double w2 = szObservations.getWeight(j);
96
97 // Longer legs receive proportionally longer weight.
98 Weight weight = std::abs(s2 - s1) * hypot2(w1, w2);
99 weightedTanLambdas.emplace_back((z2 - z1) / (s2 - s1), weight);
100 totalWeight += weight;
101 }
102 }
103
104 for (WithWeight<double>& weightedTanLambda : weightedTanLambdas) {
105 weightedTanLambda.weight() /= totalWeight;
106 }
107
108 const double tanLambda = weightedMedian(std::move(weightedTanLambdas));
109 const double z0 = getMedianZ0(szObservations, tanLambda);
110
111 CDCTrajectorySZ trajectorySZ(tanLambda, z0);
112 trajectorySZ.setNDF(szObservations.size());
113 return trajectorySZ;
114}
double getWeight(int iObservation) const
Getter for the weight / inverse variance of the observation at the given index.

◆ getMedianZ0()

double getMedianZ0 ( const CDCSZObservations & szObservations,
double tanLambda )
staticprivate

Compute the median z0 intercept from the given observations and an estimated slope.

Definition at line 116 of file CDCRobustSZFitter.cc.

117{
118 std::vector<double> z0s;
119 z0s.reserve(szObservations.size());
120 for (unsigned int i = 0; i < szObservations.size(); i++) {
121 double s = szObservations.getS(i);
122 double z = szObservations.getZ(i);
123 z0s.push_back(z - s * tanLambda);
124 }
125 const double z0 = median(std::move(z0s));
126 return z0;
127}

The documentation for this class was generated from the following files: