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