Belle II Software  release-08-01-10
QualityEstimatorTripletFit.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 <gtest/gtest.h>
10 
11 #include <vector>
12 
13 #include <framework/geometry/B2Vector3.h>
14 
15 #include "tracking/trackFindingVXD/trackQualityEstimators/QualityEstimatorTripletFit.h"
16 
17 
18 using namespace Belle2;
19 const static double allowed_chi2_deviation = 1e-20;
20 
21 
22 namespace QualityEstimatorTests {
23 
24  TEST(TripletFitTests, CircleChi2)
25  {
26  // Setup QualityEstimator
27  auto qualityEstimator = QualityEstimatorTripletFit();
28  qualityEstimator.setMagneticFieldStrength(1.5);
29 
30  // Some hitpoints that are exactly on a circle in x,y with radius 1 and m=(1,0,0)
31  auto position1 = B2Vector3<double>(0., 0., 0.);
32  auto position2 = B2Vector3<double>(1., 1., 0.);
33  auto position3 = B2Vector3<double>(2., 0., 0.);
34  B2Vector3<double> sigma;
35 
36  auto spacePoint1 = SpacePoint(position1, sigma, {0.5, 0.5}, {false, false}, VxdID(0), Belle2::VXD::SensorInfoBase::VXD);
37  auto spacePoint2 = SpacePoint(position2, sigma, {0.5, 0.5}, {false, false}, VxdID(0), Belle2::VXD::SensorInfoBase::VXD);
38  auto spacePoint3 = SpacePoint(position3, sigma, {0.5, 0.5}, {false, false}, VxdID(0), Belle2::VXD::SensorInfoBase::VXD);
39 
40  std::vector<SpacePoint const*> hitlist;
41  hitlist.reserve(3);
42  hitlist.push_back(&spacePoint1);
43  hitlist.push_back(&spacePoint2);
44  hitlist.push_back(&spacePoint3);
45 
46  // Perform fit
47  auto result = qualityEstimator.estimateQualityAndProperties(hitlist);
48 
49  ASSERT_TRUE(result.chiSquared);
50  ASSERT_NEAR(*(result.chiSquared), 0., allowed_chi2_deviation) << "1st perfect circle";
51 
52  // Some hitpoints that are exactly on a circle in rotated 2D-plane with radius 1
53  position1 = B2Vector3<double>(0., 0., 0.);
54  position2 = B2Vector3<double>(1., 1., 1.);
55  position3 = B2Vector3<double>(2., 0., 2.);
56 
57  spacePoint1 = SpacePoint(position1, sigma, {0.5, 0.5}, {false, false}, VxdID(0), Belle2::VXD::SensorInfoBase::VXD);
58  spacePoint2 = SpacePoint(position2, sigma, {0.5, 0.5}, {false, false}, VxdID(0), Belle2::VXD::SensorInfoBase::VXD);
59  spacePoint3 = SpacePoint(position3, sigma, {0.5, 0.5}, {false, false}, VxdID(0), Belle2::VXD::SensorInfoBase::VXD);
60 
61  hitlist.clear();
62  hitlist.push_back(&spacePoint1);
63  hitlist.push_back(&spacePoint2);
64  hitlist.push_back(&spacePoint3);
65 
66  // Perform fit
67  result = qualityEstimator.estimateQualityAndProperties(hitlist);
68 
69  ASSERT_TRUE(result.chiSquared);
70  ASSERT_NEAR(*(result.chiSquared), 0., allowed_chi2_deviation) << "2nd perfect circle";
71 
72  // Move one hit away from circle
73  position3 = B2Vector3<double>(2., 0., 2. + 1e-6);
74  spacePoint3 = SpacePoint(position3, sigma, {0.5, 0.5}, {false, false}, VxdID(0), Belle2::VXD::SensorInfoBase::VXD);
75 
76  hitlist.clear();
77  hitlist.push_back(&spacePoint1);
78  hitlist.push_back(&spacePoint2);
79  hitlist.push_back(&spacePoint3);
80  // Perform fit
81  result = qualityEstimator.estimateQualityAndProperties(hitlist);
82 
83  ASSERT_TRUE(*(result.chiSquared) > allowed_chi2_deviation) << "1st imperfect circle";
84 
85  // Move one hit away from circle
86  position3 = B2Vector3<double>(2. + 1e-6, 0., 2.);
87  spacePoint3 = SpacePoint(position3, sigma, {0.5, 0.5}, {false, false}, VxdID(0), Belle2::VXD::SensorInfoBase::VXD);
88 
89  hitlist.clear();
90  hitlist.push_back(&spacePoint1);
91  hitlist.push_back(&spacePoint2);
92  hitlist.push_back(&spacePoint3);
93  // Perform fit
94  result = qualityEstimator.estimateQualityAndProperties(hitlist);
95 
96  ASSERT_TRUE(result.chiSquared);
97  ASSERT_TRUE(*(result.chiSquared) > allowed_chi2_deviation) << "2nd imperfect circle";
98  }
99 
100  TEST(TripletFitTests, CombinedCircleChi2)
101  {
102  // Setup QualityEstimator
103  auto qualityEstimator = QualityEstimatorTripletFit();
104  qualityEstimator.setMagneticFieldStrength(1.5);
105 
106  // Some hitpoints that are exactly on a circle in x,y with radius 1 and m=(1,0,0)
107  auto position1 = B2Vector3<double>(0., 0., 0.);
108  auto position2 = B2Vector3<double>(1., 1., 0.);
109  auto position3 = B2Vector3<double>(2., 0., 0.);
110  auto position4 = B2Vector3<double>(1., -1., 0.);
111  B2Vector3<double> sigma;
112 
113  auto spacePoint1 = SpacePoint(position1, sigma, {0.5, 0.5}, {false, false}, VxdID(0), Belle2::VXD::SensorInfoBase::VXD);
114  auto spacePoint2 = SpacePoint(position2, sigma, {0.5, 0.5}, {false, false}, VxdID(0), Belle2::VXD::SensorInfoBase::VXD);
115  auto spacePoint3 = SpacePoint(position3, sigma, {0.5, 0.5}, {false, false}, VxdID(0), Belle2::VXD::SensorInfoBase::VXD);
116  auto spacePoint4 = SpacePoint(position4, sigma, {0.5, 0.5}, {false, false}, VxdID(0), Belle2::VXD::SensorInfoBase::VXD);
117 
118  std::vector<SpacePoint const*> hitlist;
119  hitlist.reserve(4);
120  hitlist.push_back(&spacePoint1);
121  hitlist.push_back(&spacePoint2);
122  hitlist.push_back(&spacePoint3);
123  hitlist.push_back(&spacePoint4);
124  // Perform fit
125  auto result = qualityEstimator.estimateQualityAndProperties(hitlist);
126 
127  ASSERT_TRUE(result.chiSquared);
128  ASSERT_NEAR(*(result.chiSquared), 0., allowed_chi2_deviation) << "1st perfect combined circle";
129 
130  // Combine two triplets with different radii;
131  position4 = B2Vector3<double>(1., -2., 0.);
132  spacePoint4 = SpacePoint(position4, sigma, {0.5, 0.5}, {false, false}, VxdID(0), Belle2::VXD::SensorInfoBase::VXD);
133 
134  hitlist.clear();
135  hitlist.reserve(4);
136  hitlist.push_back(&spacePoint1);
137  hitlist.push_back(&spacePoint2);
138  hitlist.push_back(&spacePoint3);
139  hitlist.push_back(&spacePoint4);
140 
141  result = qualityEstimator.estimateQualityAndProperties(hitlist);
142 
143  ASSERT_TRUE(result.chiSquared);
144  ASSERT_TRUE(*(result.chiSquared) > allowed_chi2_deviation) << "Incompatible circle triplets";
145  }
146 
147  TEST(TripletFitTests, Interface)
148  {
149  // Setup QualityEstimator Class
150  auto qualityEstimator = QualityEstimatorTripletFit();
151  qualityEstimator.setMagneticFieldStrength(1.5);
152 
153  // Some hitpoints
154  auto position1 = B2Vector3<double>(0., 0., 0.);
155  auto position2 = B2Vector3<double>(1., 1., 0.);
156  auto position3 = B2Vector3<double>(2., 0., 0.);
157  B2Vector3<double> sigma;
158  auto spacePoint1 = SpacePoint(position1, sigma, {0.5, 0.5}, {false, false}, VxdID(0), Belle2::VXD::SensorInfoBase::VXD);
159  auto spacePoint2 = SpacePoint(position2, sigma, {0.5, 0.5}, {false, false}, VxdID(0), Belle2::VXD::SensorInfoBase::VXD);
160  auto spacePoint3 = SpacePoint(position3, sigma, {0.5, 0.5}, {false, false}, VxdID(0), Belle2::VXD::SensorInfoBase::VXD);
161 
162  std::vector<SpacePoint const*> hitlist;
163  hitlist.reserve(4);
164  hitlist.push_back(&spacePoint1);
165  hitlist.push_back(&spacePoint2);
166  hitlist.push_back(&spacePoint3);
167 
168  // Test if calcChiSquared and calcCompleteResults return the same values
169  auto result = qualityEstimator.estimateQuality(hitlist);
170  auto resultObject = qualityEstimator.estimateQualityAndProperties(hitlist);
171  ASSERT_EQ(resultObject.qualityIndicator, result);
172 
173  // check if the correct optional values are set
174  ASSERT_FALSE(resultObject.p);
175 
176  ASSERT_TRUE(resultObject.chiSquared);
177  ASSERT_TRUE(resultObject.pt);
178  ASSERT_TRUE(resultObject.pmag);
179  ASSERT_TRUE(resultObject.curvatureSign);
180 
181  // Test if tripletFit handles empty measurements vector correct
182  hitlist.clear();
183 
184  result = qualityEstimator.estimateQuality(hitlist);
185  resultObject = qualityEstimator.estimateQualityAndProperties(hitlist);
186  ASSERT_EQ(result, resultObject.qualityIndicator);
187 
188  // check if the optional values got reset
189  ASSERT_FALSE(resultObject.chiSquared);
190  ASSERT_FALSE(resultObject.p);
191  ASSERT_FALSE(resultObject.pt);
192  ASSERT_FALSE(resultObject.pmag);
193  ASSERT_FALSE(resultObject.curvatureSign);
194  }
195 }
196 
does a tripletFit of the given hits The filter is based on the paper 'A New Three-Dimensional Track F...
SpacePoint typically is build from 1 PXDCluster or 1-2 SVDClusters.
Definition: SpacePoint.h:42
@ VXD
Any type of VXD Sensor.
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
Exception to be thrown in case of an empty result.
Definition: Interface.h:35
TEST(TestgetDetectorRegion, TestgetDetectorRegion)
Test Constructors.
Abstract base class for different kinds of events.