Belle II Software development
CDCRobustSZFitter Class Reference

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

#include <CDCRobustSZFitter.h>

Public Member Functions

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

Private Member Functions

double getMedianZ0 (const CDCSZObservations &szObservations, double tanLambda) const
 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 20 of file CDCRobustSZFitter.h.

Member Function Documentation

◆ fitTheilSen()

CDCTrajectorySZ fitTheilSen ( const CDCSZObservations szObservations) const

Implements the original Theil-Sen line fit algorithm.

Does not estimate the covariances of the fit parameters.

Definition at line 57 of file CDCRobustSZFitter.cc.

58{
59 std::vector<double> tanLambdas;
60 tanLambdas.reserve(szObservations.size() * (szObservations.size() - 1) / 2);
61 for (unsigned int i = 0; i < szObservations.size(); i++) {
62 for (unsigned int j = i + 1; j < szObservations.size(); j++) {
63 double s1 = szObservations.getS(i);
64 double s2 = szObservations.getS(j);
65 if (s1 == s2) continue;
66 double z1 = szObservations.getZ(i);
67 double z2 = szObservations.getZ(j);
68 tanLambdas.push_back((z2 - z1) / (s2 - s1));
69 }
70 }
71
72 const double tanLambda = median(std::move(tanLambdas));
73 const double z0 = getMedianZ0(szObservations, tanLambda);
74
75 CDCTrajectorySZ trajectorySZ(tanLambda, z0);
76 trajectorySZ.setNDF(szObservations.size());
77 return trajectorySZ;
78}
double getMedianZ0(const CDCSZObservations &szObservations, double tanLambda) const
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.
Linear trajectory in sz space.

◆ fitUsingSimplifiedTheilSen()

CDCTrajectorySZ fitUsingSimplifiedTheilSen ( const CDCSZObservations szObservations) const

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 22 of file CDCRobustSZFitter.cc.

23{
24 // This seems to be some other algorithm
25
26
27 CDCTrajectorySZ trajectorySZ;
28 CDCSZFitter szFitter;
29
30 if (observationsSZ.size() > 4) {
31 CDCSZObservations observationsSZFiltered;
32
33 double meanTanLambda = 0;
34 double meanStartZ = 0;
35
36 for (unsigned int i = 0; i < observationsSZ.size(); i++) {
37 for (unsigned int j = 0; j < observationsSZ.size(); j++) {
38 if (i != j) {
39 observationsSZFiltered.fill(observationsSZ.getS(j),
40 observationsSZ.getZ(j),
41 observationsSZ.getWeight(j));
42 }
43 } // for j
44
45 szFitter.update(trajectorySZ, observationsSZFiltered);
46 meanTanLambda += trajectorySZ.getTanLambda();
47 meanStartZ += trajectorySZ.getZ0();
48 } // for i
49
50 return CDCTrajectorySZ(meanTanLambda / observationsSZ.size(),
51 meanStartZ / observationsSZ.size());
52 } else {
54 }
55}
Class implementing the z coordinate over travel distance line fit.
Definition: CDCSZFitter.h:27
void update(const CDCSegmentPair &segmentPair) const
Updates the trajectory of the axial stereo segment pair inplace.
Definition: CDCSZFitter.cc:163
Class serving as a storage of observed sz positions to present to the sz line fitters.
std::size_t fill(double s, double z, double weight=1.0)
Appends the observed position.
static CDCTrajectorySZ basicAssumption()
Constucts a basic assumption, what the z0 start position and the sz slope are, including some broad v...
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) const

Implements the weighted Theil-Sen line fit algorithm.

Does not estimate the covariances of the fit parameters.

Definition at line 80 of file CDCRobustSZFitter.cc.

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

◆ getMedianZ0()

double getMedianZ0 ( const CDCSZObservations szObservations,
double  tanLambda 
) const
private

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

Definition at line 115 of file CDCRobustSZFitter.cc.

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

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