Belle II Software  release-06-00-14
QualityEstimatorLineFit3D.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #include "tracking/trackFindingVXD/trackQualityEstimators/QualityEstimatorLineFit3D.h"
10 #include <math.h>
11 #include <TMath.h>
12 
13 using namespace Belle2;
14 
15 double QualityEstimatorLineFit3D::estimateQuality(std::vector<SpacePoint const*> const& measurements)
16 {
17  TVector3 directionVector;
18  double sumWyi = 0, // sum of weights for Yi
19  sumWzi = 0, // sum of weights for Zi
20  sumWyiXi = 0, // sum of (y-weights times x-values)
21  sumWziXi = 0, // sum of (z-weights times x-values)
22  sumWyiYi = 0, // sum of (y-weights times y-values)
23  sumWziZi = 0, // sum of (z-weights times z-values)
24  sumWyiXiYi = 0, // sum of (y-weights times x-values times y-values)
25  sumWziXiZi = 0, // sum of (z-weights times x-values times z-values)
26  sumWyiXi2 = 0, // sum of (y-weights times x-values^2)
27  sumWziXi2 = 0, // sum of (z-weights times x-values^2)
28  detValY = 0, // determinant for norming values - y
29  detValZ = 0, // determinant for norming values - z
30  slopeY = 0, // = a of model
31  slopeZ = 0, // = c of model
32  chi2 = 0, // final chi2-value of fit
33  interceptY = 0, // b of model, needed only for chi2-calculation
34  interceptZ = 0; // d of model, needed only for chi2-calculation
35 
36  // NOTE: this approach is not optimal. Maybe can be optimized for less redundancy
37  for (const SpacePoint* aHit : measurements) {
38  double Wyi = (1. / (aHit->getPositionError().Y() * aHit->getPositionError().Y()));
39  double Wzi = (1. / (aHit->getPositionError().Z() * aHit->getPositionError().Z()));
40 
41  sumWyi += Wyi;
42  sumWzi += Wzi;
43 
44  sumWyiXi += Wyi * aHit->getPosition().X();
45  sumWziXi += Wzi * aHit->getPosition().X();
46 
47  sumWyiYi += Wyi * aHit->getPosition().Y();
48  sumWziZi += Wzi * aHit->getPosition().Z();
49 
50  sumWyiXiYi += Wyi * aHit->getPosition().X() * aHit->getPosition().Y();
51  sumWziXiZi += Wzi * aHit->getPosition().X() * aHit->getPosition().Z();
52 
53  sumWyiXi2 += Wyi * aHit->getPosition().X() * aHit->getPosition().X();
54  sumWziXi2 += Wzi * aHit->getPosition().X() * aHit->getPosition().X();
55  }
56 
57  detValY = sumWyiXi2 * sumWyi - sumWyiXi * sumWyiXi;
58  if (detValY == 0) {
59  return 0;
60  }
61  detValY = 1. / detValY; // invert
62 
63  detValZ = sumWziXi2 * sumWzi - sumWziXi * sumWziXi;
64  if (detValZ == 0) {
65  return 0;
66  }
67  detValZ = 1. / detValZ; // invert
68 
69  slopeY = detValY * (sumWyi * sumWyiXiYi - sumWyiXi * sumWyiYi);
70  slopeZ = detValZ * (sumWzi * sumWziXiZi - sumWziXi * sumWziZi);
71 
72  interceptY = detValY * (- sumWyiXi * sumWyiXiYi + sumWyiXi2 * sumWyiYi);
73  interceptZ = detValZ * (- sumWziXi * sumWziXiZi + sumWziXi2 * sumWziZi);
74 
75  for (const SpacePoint* aHit : measurements) { // chi2 of xy-fit and of xz-fit can be combined by adding their values
76  chi2 += pow(((aHit->getPosition().Y() - slopeY * aHit->getPosition().X() - interceptY) / aHit->getPositionError().Y()) , 2)
77  + pow(((aHit->getPosition().Z() - slopeZ * aHit->getPosition().X() - interceptZ) / aHit->getPositionError().Z()) , 2);
78  }
79  m_results.chiSquared = chi2;
80 
81  //m_results.p = B2Vector3<double>(1, slopeY, slopeZ);
82 
83  return TMath::Prob(chi2, measurements.size() - 1);
84 }
85 
QualityEstimationResults m_results
Result of the quality estimation This is stored as a member variable, because some values may be calc...
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.
Definition: SpacePoint.h:42
Abstract base class for different kinds of events.
boost::optional< double > chiSquared
chi squared value obtained by the fit of the QE